While Loops
Runs while the conditions following “while” are true - possibly forever!
To “break” out of the loop, update a “control variable” in the loop so eventually the conditions will be false
While loop example
Processing, Java, C#:
JavaScript and JS libraries:
Both will print:
0 1 2 3 4
Here:
Type: while (line 3)
Initialization: int count = 0; and var count = 0; (line 1)
Conditions: (count < 5) (line 3) (only runs the loop code when the count is 0-4)
Update: count++; (line 5)
Action: println(count); (line 4) (prints the current value of count)
Last updated