Skip to content

Control Flow

Conditions and loops are tree nodes like any other statement. The interpreter does not compile them to jumps. It evaluates the condition, and either walks the body or skips it.

A condition must already be a boolean. The walk does not treat a number, a string, or a list as true or false. and and or are their own nodes so the right operand is evaluated only when the left operand does not decide the result. not requires a boolean as well.

Loops

while evaluates its condition before every iteration.

A numeric for evaluates the start, end, and step once, then keeps its own counter. The default step is 1 . A step of 0 is a value error. The body may assign to the loop variable, and the next iteration still writes the next counter value at the start of the body. The loop variable is created in the current scope when that name is not already there.

for ... in takes a snapshot of the collection before the first iteration. A list yields its elements, a string yields its characters, and a dictionary yields its keys in insertion order. Changing the collection in the body does not change that snapshot.

break and continue are internal signals, not Lupe errors. They unwind only to the innermost loop. The parser has already rejected either word outside a loop, so the interpreter does not have to look for a missing loop at run time.