O'Reilly logo

Python: Visual QuickStart Guide, Second Edition by Toby Donaldson

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 4. Flow of Control

The programs we’ve written so far are straight-line programs that consist of a sequence of Python statements executed one after the other. The flow of execution is simply a straight sequence of statements, with no branching or looping back to previous statements.

In this chapter, we look at how to change the order in which statements are executed by using if-statements and loops. Both are essential in almost any nontrivial program.

For many beginners, if-statements and loops are two of the trickiest parts of learning how to program. Loops, in particular, can be confusing at first because they require a lot of little pieces of code to work correctly.

So take this chapter slowly and read through the sample programs carefully. ...

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