O'Reilly logo

Hello World! Computer Programming for Kids and Other Beginners by Carter Sande, Warren Sande

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Nested and Variable Loops

We already saw that, within the body of a loop (which is a block of code), we can put other things that have their own blocks. If you look at the number-guessing program from chapter 1, you’ll see this:

The outer, light gray block is a while loop block, and the dark gray blocks are if and elif blocks within that while loop block.

You can also put a loop within another loop. These loops are called nested loops.

Nested loops

Remember the multiplication table program you wrote for the “Try it out” section in chapter 8? Without the user-input part, it might look something like this:

multiplier = 5                                   
for i ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required