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.
The if statement is the fundamental decision control structure that enables alternative code blocks to ...