while loop


While Loop

A while loop repeatedly executes a block of code as long as its condition evaluates to true. The condition is checked before each iteration.

    
count := 0;
while count < 5 {
    print("% ", count);  // Outputs: 0 1 2 3 4
    count += 1;
}
    

Use while loops when you don't know in advance how many iterations you need, or when the loop's continuation depends on a dynamic condition.