Chapter I · Language basics / Lesson 4 of 27

Control flow

You'll learn: Use if, while, repeat..until, and numeric for with explicit steps.

if/elseif/else are statements, not expressions. while checks before entering the body; repeat..until checks after, so the body always runs at least once. Numeric for takes start, stop[, step] — a negative step counts down. See *Iteration* for the generic for.

control-flow.lua
Output idle
Hit Run to execute.
Try it: Rewrite the while loop as a repeat..until. Then flip the initial value of i to 5while skips, repeat still runs once.