For Loops

Wikipedia: For loop
for is Tengo's only looping construct. It supports several forms.

fmt := import("fmt")
n := 1
for n < 5 {
    fmt.println(n)
    n++
}
for i := 0; i < 3; i++ {
    fmt.println("i = ", i)
}
for i := 0; i <= 5; i++ {
    if i % 2 == 0 {
        continue
    }
    fmt.println(i)
}
fruits := ["apple", "banana", "cherry"]
for i, fruit in fruits {
    fmt.printf("%v -> %v\n", i, fruit)
}
scores := {alice: 95, bob: 87}
for name, score in scores {
    fmt.printf("%v scored %v\n", name, score)
}

try it

1
2
3
4
i = 0
i = 1
i = 2
loop
1
3
5
0 -> "apple"
1 -> "banana"
2 -> "cherry"
"alice" scored 95
"bob" scored 87
loading…