Our next control structure is a loop. While conditional statements allowed us to execute certain lines of code only under given circumstances, loops allow us to repeat certain lines of code until some condition is met.
Another word that we use to talk about repeating code is iterating or iteration.
Loops are an extremely powerful tool. They will help us write programs that play games, calculate interest over time, graph trends from data, and do a whole slew of other things.
Remember, in these notes we are looking at these control structures in isolation, but they are most powerful when they are used together.
In this chapter, we’ll cover while
loops. For notes on for
loops, see the “For Loops” chapter.