StudyToCert

All certifications / PCEP / Lessons

PCEP – Certified Entry-Level Python Programmer PCEP-30-02 · Domain 2: Control flow: conditional blocks and loops

While-else and for-else: when the else clause runs and when break skips it

▶ Watch the overview video

Last reviewed September 30, 2026 · Leer en español

Python lets a loop have an else clause, which surprises people who know else only from if. The else block is written at the same indentation as the for or while header and runs once, after the loop, if the loop finished normally. "Normally" means the while condition became false or the for loop ran out of items. If the loop was ended by break, the else block is skipped.

Free account

Keep reading for free

Create a free StudyToCert account to read the rest of this lesson: 7 more sections, 5 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.

Sign up free Log in

Study PCEP for free
A week-by-week plan with every lesson, quizzes, checkpoint tests, a practice exam and hands-on labs.
Open the PCEP study plan