While statement

Syntax

while contidion {
    // statements
}

The code inside while statement will be executed looply until the condition is false.

Counting

var i = 0
while i < 10 {
    i++
    puts i
}

Infinite loop

while true {
    // do something
}

Consider before using the infinite loop, that will make your program gets stuck.

Last updated

Was this helpful?