Loops let you repeat code multiple times. BER supports a for
loop that runs a block of code for a set number of times.
for i is 1 to 5
board:(i)
end
Explanation: This loop prints numbers 1 to 5.
The syntax is for <variable> is <start> to <end>
followed by the loop body, closed with end
.
table names is ["Bernardo", "Ana", "Luca"]
for i is 1 to 3
board:(names(i))
end
This example prints each name in the names
table.
end
to close loops to avoid syntax errors.