Lesson 6Controlling Program Flow with Loops

As you learned in the previous lesson, without specific  instructions, a program executes statements linearly until the program ends or until an error causes the program to fail. You also saw how to change the flow of your programs based on conditions.

In this lesson, you will learn how to repeat a line of code or set of instructions. We will look at the use of looping to control the flow of a program during runtime as well as cover a few related items for adjusting the flow of a program from within a loop.

LOOPING STATEMENTS

In every programming language, it is important to be able to repeat statements without having to write the statements over and over. For example, Listing 6.1 uses only what you've learned so far to print the values 1 to 10 using a single variable.

When you run this listing, ...

Get Job Ready Go 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.