Python · Beginner level

Beginner level · Module 2 of 5 · 10 guided hours

Decisions and Loops

Make programs choose between actions and repeat work automatically, the core of every automation script.

Learning objectives

  • Write conditions with comparison and boolean operators
  • Use for and while loops to process many values
  • Control loops with break and continue

Topics

  • if / elif / else
  • comparison and boolean operators
  • for loops and range()
  • while loops, break and continue

Lessons

  1. Lesson 1 Conditions with if, elif and else

    Write programs that take different actions depending on the data, such as grading a score or applying a discount.

    boolean expressionelif chainindentation block

  2. Lesson 2 for Loops and range()

    Repeat an action for every item in a collection or for a fixed number of times.

    iterationrange(start, stop, step)accumulatorenumerate()

  3. Lesson 3 while Loops, break and continue

    Repeat until a condition changes, such as a menu that runs until the user chooses to exit.

    loop conditioninfinite loopsentinel valuebreak/continue

Practical activity

Attendance threshold checker: process a list of learners' attendance counts and print who is eligible for a certificate (80%+), who needs a make-up session (60–79%) and who is at risk.

Expected outcomes

  • Programs that make correct decisions at boundary values
  • Loops that process whole lists and always terminate

Assessment

Short practical test: two small loop/condition tasks completed in class within 30 minutes, marked for correct output and clean structure.

Free taster lesson Control Flow: Conditions & Loops Read a free self-study lesson on this topic in the Free Course Library.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.