Chapter 4

Control Flow

conditionalsfor loopswhile loopsbreakcontinue

Learning Path

Hands-on Labs

Each objective has a coding lab that opens in VS Code in your browser

Objective 1

Make decisions with if/elif/else

Goal

You will control program flow with conditional statements. Write simple if statements, handle multiple conditions with elif, and nest if statements for complex logic.

Objective 2

Iterate with for loops

Goal

You will iterate over sequences with for loops. Loop through ranges of numbers, iterate over strings character by character, and use enumerate to get both index and value.

Objective 3

Repeat with while loops

Goal

You will use while loops for conditional repetition. Create countdown loops, loop until a condition is met, and learn to avoid infinite loops with proper exit conditions.

Objective 4

Control loop execution

Goal

You will control loop execution with break and continue. Use break to exit loops early when a condition is met, use continue to skip specific iterations, and combine these with conditionals.