math.min

math.min
Function
Syntax
math.min(
  • numbers... : number
)

Returns number
API math
Source Lua (source)

Return the smallest of all the numbers given.

ExamplePrint the minimum value of user input
Read as many lines as the user inputs, and return the smallest value that they wrote.
Code
<nowiki>
local max = math.huge
while true do
  local l = read()
  if tonumber(l) then
    max = math.min(max, tonumber(l))
  else
    break
  end
end
print(max)
    </nowiki>
Output The line the user wrote with the smallest value, or inf if they wrote no lines.
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.