next

From ComputerCraft
Jump to navigation Jump to search

next
Function
Syntax
next()
Returns various index, various value
API Base globals
Source CC:Tweaked

Gets the next index and its value of the table table starting at index. If index is nil, then it returns an initial index and value. This function returns nil if called with the last index or table is nil. However, the order that indices are returned are not in order, even if table has numerical indices.

ExampleExampleCheck if a table is empty
Errors if table is empty, or prints the table's contents.
Code
local t1 = {}
if next(t1) then
  print(textutils.serialize(t1))
else
  error("empty table", 2)
end
Output
program.lua:4:empty table