math.max

From ComputerCraft
Jump to: navigation, search

math.max
Function
Syntax
math.max()
Returns number
API math
Source Lua (source)

Return the greatest of all the numbers given.

ExampleExamplePrint the maximum value of user input
Read as many lines as the user inputs, and return the greatest value that they wrote.
Code
local max = -(1/0) -- negative infinity
while true do
  local l = read()
  if tonumber(l) then
    max = math.max(max, tonumber(l))
  else
    break
  end
end
print(max)
Output The line the user wrote with the greatest value, or inf if they wrote no lines.