there are 3 types of primitive loops: for, while and repeat.
For loops repeat the instructions for the given amount of times
for i = 1, 9 do -- for 1 - 9 do
for i = 1, 9, 2 do -- for 1, 3, 5, 7, 9 do
for i = 9, 1, -1 do -- for 9-1 do
while loops run until the conditional is true
i = 1
while 1 ~= 9 do
-- do something
i = i + 1
end
repeat loops always run the instructions at least once, and after completion of the instructions will evaluate if it should continue
i = 1
repeat
-- do something
i = i + 1
until i == 8
NOTE: we use 8 here because it already has run it once, so we want it to run n - 1 times…