Lesson 04: Iteration and control flow (part II)

This week we continue exploring iteration and a program’s control flow. You will learn how to perform indefinite iteration using a while loop and manage the number of iterations given some condition using a “counter” value along with continue and break statements.

You will also learn how to write conditional statements that test multiple conditions or test the inverse of a condition using the logical operators (and, or, not).

Readings

Below are a set of readings that you should consider reviewing. Note that the Real Python articles referenced below may require signing up for a free account.

1.0 Required

Eric Matthes, Python Crash Course, 3rd Edition (No Starch Press, 2023).

Read Chapter 7, User Input and While Loops.

Eric discusses the built-in function input(), the while loop, and continue and break statements.

Leodanis Pozo Ramos, Using the 'and' Boolean Operator in Python (Real Python, Sep 2021).

Discusses Boolean logic with special emphasis on the Python and operator.

Leodanis Pozo Ramos, Using the 'or' Boolean Operator in Python (Real Python, Jul 2019).

Discusses Boolean logic with special emphasis on the Python or operator.

Charles Severance, Python for Everybody. Exploring data in Python 3 (CreateSpace, 2016).

💡 An English-language version of Chuck’s book is available as a PDF or ePub in the Canvas Files texts folder. Other translations and formats are available online.

Read Chapter 3, “Conditional Execution”. Chuck discusses boolean expressions, logical operators, conditional execution, chained/nested conditionals, and try/except blocks.

Read Chapter 5 “Iteration”. Chuck covers the while statement, the control flow statements break and continue, and the for loop.

Lisa Tagliaferri, How to Construct While Loops in Python 3 (Digital Ocean, Jan 2017).

Discusses indefinite iteration using the while loop with examples using the built-in function input().

Lisa Tagliaferri, How to Use Break, Continue, and Pass Statements when Working with Loops in Python 3 (Digital Ocean, Jan 2017).

Read Lisa to deepen your understanding of control flow and how to use break, continue, and pass in your for loops.

3.0 Reference

Eric Matthes, Beginner’s Python Cheat Sheet - If Statements and While Loops.