Lynxer

Documentation

Loops

Lynxer has five loop keywords: while, for, doWhile, iterate and forever. Every one takes parentheses; forever and the condition-less doWhile are written forever(){ ... } and doWhile(){ ... }.

while

while (n > 0) {
    n -= 1;
}

for

for has two forms: the C style and the range style.

C style

for (int i = 0; i < 3; i = i + 1) {
    println(i);
}

for (int i = 0; i < 3) {   // update omitted: the increment is implicit
    println(i);
}

i++ and i-- do not exist — use i = i + 1, i += 1, or the implicit update.

Range style

The range form iterates an integer variable over a range of values:

for (int i = 0..=10..2) { ... }   // 0, 2, 4, 6, 8, 10
for (int i = 0..10..2) { ... }    // 0, 2, 4, 6, 8
for (int i = 1..=3..1) { ... }    // 1, 2, 3
for (int i = 1..=3) { ... }       // 1, 2, 3 — the step defaults to 1
for (int i = 10..=0..-2) { ... }  // 10, 8, 6, 4, 2, 0

The header is for (<type> <name> = <start> (.. | ..=) <end> [.. <step>]):

break and continue work as in any loop.

LoopValues
for (int i = 0..=10..2)0, 2, 4, 6, 8, 10
for (int i = 0..10..2)0, 2, 4, 6, 8
for (int i = 0..=3..1)0, 1, 2, 3
for (int i = 0..0..1)(no iterations)
for (int i = 10..=0..-2)10, 8, 6, 4, 2, 0
for (int i = 3..0..-1)3, 2, 1

lynxer/examples/range_for.lynx pins all of these.

doWhile

doWhile (n < 3) {          // tests before each pass after the first
    n += 1;
}

doWhile(){                 // no-condition form: loops until `break`
    n += 1;
    if (n > 9) { break; }
}

iterate

iterate (4) {              // exactly four iterations
    println("tick");
}

iterate(count) requires an integer count.

forever

forever(){                 // loops until `break`
    if (done) { break; }
}

forever() without a reachable break prints a warning unless suppressForeverWarning() was called in setup().

break, continue, restart

See also