Codele / Programming basics
While loops
A computer never gets bored. Tell it to repeat the same lines while a question stays “yes”, and it keeps going until the answer turns “no”.
- while asks a yes or no question before every round. Yes: run the lines inside. No: stop.
- The question is asked again after each round, with the box’s new value.
- Something inside the loop must change the box, or the answer never turns no.
- A loop that never stops is an endless loop. It is a common mistake, and everyone makes it once.
- If the question is “no” the first time, the loop runs zero times.
Loading the playable lesson…