Control Flow

3. Control Flow#

Control flow lets a program decide what to do next. This chapter introduces the branching and looping structures that turn straight-line code into programs that respond to data.

  • Conditional statements with if, elif, and else

  • for loops for iterating over data

  • while loops for condition-based repetition

  • Loop-control keywords for special cases

Video

This overview introduces Boolean expressions and conditional branches with if, elif, and else.

Learning Goals

By the end of this chapter, you will be able to:

  1. Use conditional statements to choose between branches of code

  2. Write for and while loops for repeated work

  3. Use break, continue, and pass intentionally

  4. Trace how control moves through nested branches and loops

Chapter Flow

Chapter Overview Slides