Python Tutorial · Revision notes

Python Control Statements

Control statements decide which code runs and how many times. This chapter covers if else, for and while loops, break, continue, pass and the differences between them.

Quick revision

  • if-elif-else: first true condition runs; indent blocks; end headers with a colon.
  • == compares, = assigns; empty containers, 0 and None are falsy.
  • for iterates over an iterable; range(stop) excludes stop; use enumerate and zip.
  • while repeats while the condition is true; always update the condition variable; no do-while in Python.
  • break exits the nearest loop; continue skips to the next iteration; pass does nothing.
  • Loop-else runs only when the loop finishes without break.
  • break vs continue: stop loop vs skip one round.
  • for vs while: known items/count vs unknown count or event-based stop.
Read the full Python Control Statements notes on Doubtclip →