Version 3 of max

Updated 2007-11-01 09:05:53 by dkf

max(2,3,4,5,6,-99)

Various ways: in a loop (works for numeric and string values):

 proc max list {
    set res [lindex $list 0]
    foreach element [lrange $list 1 end] {
       if {$element > $res} {set res $element}
    }
    set res
 }

By sorting (this is for numeric values only):

 proc max list {lindex [lsort -real $list] end}

In Tcl 8.5, the expr command has a max() function.


See also Reinhard Max