User:OrenBochman/Lua Loops

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search

Loops[edit]

Do Block[edit]

do
...
end

Do While Loop[edit]

while cond do
...
end

Repeat Loop[edit]

repeat
...
until cond


For Loop - Numeric[edit]

  • variable i is local to the loop block
for i = start, stop do
...
end

For Loop - Generic[edit]

  • uses a keyword - in
  • variable i is local to the loop block
for i in iterator do
...
end
  • iterator is a function returning a list of remaining values. Standard iteritors are
    • Pairs
    • iPairs