while
Repeats as long as the condition is true.
Syntax
while (condition) { ... }Description
while is used when the number of iterations is not known in advance. Don't forget to advance the counter, otherwise, it will be an infinite loop.
Example
Loading editor…
This language is for reference/learning only — copy the code and try it in your own environment.
Expected output
0 1 2
When to use?
Conditional repetition.