Difference between revisions of "Next"

From ComputerCraft
Jump to navigation Jump to search
(Created page with "{{API doc function | name = next | description = Gets the next index and its value of the table {{argument reference|type=table|name=table}} starting at {{argument reference|t...")
 
 
(One intermediate revision by the same user not shown)
Line 18: Line 18:
 
   error("empty table", 2)
 
   error("empty table", 2)
 
end
 
end
| output_raw = program.lua:2:empty table
+
  | output_raw = program.lua:4:empty table
 +
  }}
 +
}}

Latest revision as of 08:01, 10 September 2019

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