Loop Control in Python

For-SchleifeListen

Loops repeat code, but sometimes you need more control: exit early, skip an iteration, or run code only when the loop finishes normally.

Python provides break, continue, pass, and an else clause for loops. These statements help write more precise and efficient code.

We'll look at each one with examples in both while and for loops.

break – Exit the Loop Early

break immediately stops the loop, even if the condition is still true. Execution continues after the loop.

Common use: stop when a condition is met (like finding an item).

In for loop:

continue – Skip to Next Iteration

continue skips the rest of the current iteration and jumps to the next one.

Common use: skip certain values (like even numbers).

In for loop:

pass – Do Nothing

pass is a null operation – it does nothing. Use it as a placeholder when code is required syntactically.

else Clause in Loops

The else block runs when the loop finishes normally (condition false or sequence ended) – but not if break was used.

Useful for 'search not found' cases.

Quick Quiz

Wir haben die Materialien überprüft, dennoch können Fehler vorkommen. Der Inhalt dient ausschließlich Bildungszwecken, daher verwende ihn auf eigene Verantwortung und überprüfe ihn bei Bedarf mit anderen Quellen.

✨ Frag Lara — deine KI-Lernpartnerin

Entsperre personalisierte Lernunterstützung. Lara kann Lektionen erklären, Themen zusammenfassen und deine Lernfragen beantworten — verfügbar ab dem Go-Tarif.


Lara hilft dir, schneller zu lernen — exklusiv für ReadyTools Go-, Plus- und Max-Mitglieder.

Verfolge deinen Fortschritt 🚀

Lerne einfacher, indem du deinen Fortschritt kostenlos verfolgst.