Learn creative coding writing simple programs

23. Using the while loop

Introduction to the while loop. The 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!


Code editor

You can make changes to the code below. Then
Below you can ask and answer questions related to this video. If your question is unrelated to the video, please post it at the Processing Forum as I'm unable to help with all of your programs and still have enough free time to eat and sleep :)
comments powered by Disqus