O'Reilly logo

Introduction to Computing Using Python: An Application Development Focus by Ljubomir Perkovic

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 5

Execution Control Structures

5.1 Decision Control and the if Statement

5.2 for Loop and Iteration Patterns

5.3 More on Lists: Two-Dimensional Lists

5.4 while Loop

5.5 More Loop Patterns

5.6 Additional Iteration Control Statements

Chapter Summary

Solutions to Practice Problems

Exercises

Problems

THIS CHAPTER COVERS, in more depth, the Python statements and techniques that provide control over what code blocks will be executed when, and how often.

We start the discussion with the Python decision control structure, the if statement. The if statement was introduced in Chapter 3 in its one-way and two-way formats. We introduce here the general format: a multiway decision control structure that allows an arbitrary number of conditions and associated alternative code blocks to be defined.

We provide next an in-depth coverage of the Python iteration control structures and techniques. Two Python statements provide the ability to execute a block of code repeatedly: the for loop and the while loop. Both are used in many different ways. The bulk of this chapter is spent on the different iteration patterns, and when and how to use them.

Understanding different iteration patterns is really about understanding different approaches to breaking up problems and solving them iteratively. This chapter is thus fundamentally about problem solving.

5.1 Decision Control and the if Statement

The if statement is the fundamental decision control structure that enables alternative code blocks to ...

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