Skip to content

while loops

Read · 1 of 4

while: keep going until it's false

while (condition) { … } checks the condition, runs the body, and checks again, over and over, until the condition is false.

Use it when you don't know in advance how many rounds you'll need. Make sure something in the body moves towards stopping, or it never ends.