May 2017
Intermediate to advanced
416 pages
21h 33m
English
There are two loop formats: one for iterating numeric indexes and another one for working with iterators. See the following code:
for x = 1,1337 do print(x) end
The step number (which can be negative) can be set by passing a third argument to the loop statement:
for x = 1337,1,-1 do print(x) end
The output will be as follows:
1337 1336 1335 … 1
For loops must end with the terminator keyword end.
The iterator function pairs() allows iteration through key and values of a given table:
t = {} t[“nmap”] = “FTW” t[1337] = “b33r” for index, value in pairs(t) do print(index, value) end
The preceding snippet will produce the following output:
nmap, ftw 1337, b33r
The items returned by the iterator pairs() is not guaranteed ...
Read now
Unlock full access