Hamilton LaboratoriesHamilton C shell 2012User guideSamples

max.csh

Oregon Coast

max.csh
Previous | Next

#  Find the maximum numeric value out of a list.  If none of the elements
#  are numeric, return 0.

#  Copyright (c) 1996-2012 by Hamilton Laboratories.  All rights reserved.

proc max( values )
   local i, j
   @ j = 0
   if ($#values) then
      for i = 0 to $#values - 1 do
         if (isnumber(values[i])) then
            @ j = values[i]
            break
         end
      end
      for i = i + 1 to $#values - 1 do
         if (isnumber(values[i]) && values[i] > j) @ j = values[i]
      end
   end
   return j
end

max $argv

Previous | Next