Python 2.4The video for this lesson is on its way.
Everything else is ready: study the parts, the key terms and the quiz below.
Python 2.4Code walkthrough8 parts
break, continue and else on Loops
Control a loop from the inside.
Loading your progress…Next: 3.1 Lists
In this lesson8 parts
- 01Three attempts
- 02break: leaving a loop early
- 03continue: skipping one iteration
- 04The loop else: when a loop ends without break
- 05What the loop else does not mean
- 06while True, and break
- 07Where break and else mislead
- 08Recap, your challenge, and the module
Key terms
The words this lesson introduces, each in one line. The module’s glossary collects them all.
- break
- Ends the loop at once; the program continues with the first line after it. It ends only the loop it is directly in.
- continue
- Ends this iteration; the loop goes on with the next item, or checks its condition again.
- loop else
- A block written at the same level as a
fororwhile, that runs when the loop ends withoutbreak.
Quiz 5 questions
Your first pick on each question is the one that counts, and a right one earns a coin. Getting one wrong here is how the lesson sticks.
Practice
Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.
The self-checking notebook for this lesson is Notebook 2 · Loops.
Common mistakes
What you will see when it goes wrong, why it happens, and the fix.
Where it’s used
Where this lesson’s ideas turn up in real work.