GSET
Language Guide

Loops

while, do…while, for, and for…in in GSET.

Implemented

while

var count = 3
while count > 0 {
    print(count)
    count = count - 1
}
TargetOutput
Pythonwhile count > 0:
JavaScriptwhile (count > 0) {
Gofor count > 0 {

The Go emitter rewrites while to for, which is why this still compiles for Go.

for (classic)

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

The Go emitter rewrites it to for i := 0; i < 5; i++ {; JavaScript gets for (let i = 0; i < 5; i++) {; Python gets a while loop with manual counter.

for … in (foreach)

The foreach keyword (or for k, v in coll) iterates collections:

var nums = [10, 20, 30]
foreach n in nums {
    print(n)
}
TargetOutput
Pythonfor n in nums:
JavaScriptfor (n of nums) {
Gofor _, n := range nums {

Two-variable form iterates maps/entries:

var scores = {"Ada": 90, "Grace": 85}
foreach name2, score in scores {
    print(name2, score)
}

do … while

Runs the body at least once:

var i = 0
do {
    print(i)
    i = i + 1
} while i < 3
TargetOutput
Pythonwhile True: + manual break on condition
JavaScript / Godo { … } while (i < 3);

break / continue

foreach n in nums {
    if n == 0 {
        break
    }
    if n < 0 {
        continue
    }
    print(n)
}

Maps directly to each target's native keywords.

On this page