Haig Armen Educational Archive

The While Loop

by Haig. Average Reading Time: less than a minute.

The ‘While’ structure is similar to an if statement, but there is an important difference. With an if statement, the code inside the curly braces will run 0 or 1 times (0 times if the condition is false, 1 time if the condition is true).

But with the while loop code can run many times, not only 0 or 1. It will keep running while the test condition is true. It is ideal to repeat some code many times.

In our example we use it to draw many circles. Just changing one value we can decide if we want 10 circles or 100. It’s important that something inside the while loop will make the condition false, otherwise the loop runs forever and can make our computer slow. Always check that the loop will run only as many times as you expect, not forever!

No comments on ‘The While Loop’

Leave a Reply