Skip to content
Rohan Singh edited this page Aug 21, 2014 · 4 revisions

All loops support the continue and break statements. continue will skip to the next iteration while break will terminate the loop.

while

var i = 1;
while (i <= 10) {
    print(i++);
}

do-while

var i = 1;
do {
    print(i++);
} while (i <= 10);

for

for (var i = 1; i <= 10; i++) {
    print(i);
}

foreach

foreach loops are used to loop through sequences.

seq oneToTen() {
    for (var i = 1; i <= 10; i++)
        yield i;
}

foreach (var i in oneToTen()) {
    print(i);
}