Plange


evaluate the second expression repeatedly while the second expression is true, all after evaluating the optional STATEMENT_SCOPE

syntax

"for" {IC} "(" {IC} [ STATEMENT_SCOPE {IC} ] EXPRESSION {IC} ";" {IC} [ ASSIGNMENT_CHAIN {{IC} "," {IC} ASSIGNMENT_CHAIN} {IC} ] ")" {IC} EXPRESSION

Example

for (x ← 0; x < 100; x++) {
    print_line(x);
};

demonstrates the optional statement_scope

Example

spammer := (<UInt> count) {
    for (count > 0; count--; ) {
        print("SPAM!!!\n");
    };
};

more than one statement may be used to initialize, and a blank may be used for the increment expression

Example

mergeSorted := (List<Int> a, List<Int> b) {
    List<Int> result;
    <Int>i;
    <Int>j;
    for (i ← 0; j ← 0; i < a.count && j < b.count; ) { //blank increment expression
        if (a[i] < b[j]) {
            result.add(a[i]);
            i++;
        } else {
            result.add(b[j]);
            j++;
        }
    }
    for (i < a.count; i++) {
        result.add(a[i])
    }
    for (j < b.count; j++) {
        result.add(b[j]);
    }
    return result;
}

copyright © Brent Lewis 2017