for loops

There are 6 types of for loops in langur.

3 part for init; test; increment { ... }
1 part for test { ... }
unlimited for { ... }
for in for .x in expr { ... }
for of for .x of expr { ... }
variable-free for of for of expr { ... }
3 part
for init; test;
increment { ... }
1 part
for test { ... }
unlimited
for { ... }
for in
for .x in expr { ... }
for of
for .x of expr { ... }
variable-free for of
for of expr { ... }

3 part for loop

You can omit any section from a 3 part loop, but not the 2 semicolons.

The init and increment sections are each a comma-delimited list (may contain multiple expressions).

1 part for loop

A 1 part loop (test only) uses no semicolons.

general rules

No parentheses are used.

Curly braces are required on the for loop body.

Langur uses 1-based indexing.

for in/of

A for in loop iterates over the values of an array or string, or over a range or number (implicit 1-based range).

A for of loop iterates over the index itself. These will loop the number of times specified by the number (or range), or the length of the array or string.

Given a descending range or number less than 1, a for of loop will not run, but not throw an exception either.

A for in loop will run with an ascending or descending range, or negative number, but not 0.

Loop control variables of for in and for of are protected. Also, the set of values to loop over is evaluated once.

A for in/of loop does not accept floating point numbers or ranges.

break / next

Use break to break out of a loop, and next to try the next iteration.

These keywords apply only to loops (never to given expressions).