Inherited from v1.0.0

while keyword

while runs its body repeatedly as long as its condition is true. The Bangla form যতক্ষণ is equivalent.

The condition is re-evaluated before each iteration. If it starts out false, the body runs zero times.

Syntax

while (<condition>) {
    // body
}

Examples

A counted loop (replaces C-style for):

var i = 0;
while (i < 5) {
    print("tick", i);
    i = i + 1;
}

Bangla form:

চলক i = 0;
যতক্ষণ (i < 5) {
    print("tick", i);
    i = i + 1;
}

Early exit and skip

Use break to exit the loop and continue to skip to the next iteration:

var i = 0;
while (i < 10) {
    i = i + 1;
    if (i == 7) { break; }
    if (i % 2 == 0) { continue; }
    print(i);
}
// 1
// 3
// 5

See also

  • for / of — when you have a list to iterate.