Title here
Summary here
Lua’s for
loop is versatile and can be used in several ways. Here are some basic types of for
loops in Lua.
When you run this script, you’ll see:
In Lua, the for
loop can be used in two main ways:
for
: Used when you know the number of iterations in advance.for
: Used with iterator functions like pairs
or ipairs
to traverse tables.The while
loop in Lua is equivalent to the condition-only for
loop in some other languages. Lua doesn’t have a built-in continue
statement, but in Lua 5.2 and later, you can simulate it using goto
.
We’ll see some other loop forms later when we look at iterators, coroutines, and other data structures.