Chapter 4. Loops Are Fun (You Can Say That Again)

We’ve used loops since our very first program to draw repeating shapes. Now it’s time to learn how to build our own loops from scratch. Whenever we need to do something over and over again in a program, loops allow us to repeat those steps without having to type each one separately. Figure 4-1 shows a visual example—a rosette made up of four circles.

A four-circle rosette pattern

Figure 4-1. A four-circle rosette pattern

Let’s think about how we might write a program to draw four circles overlapping as shown. As you saw in Chapter 2, Turtle’s circle() command draws a circle with the radius we specify inside its parentheses. Those ...

Get Teach Your Kids to Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.