Repeat work over a collection or until a condition fails: for and while loops, break and continue, and loops nested inside one another.
No account needed to read a lesson · 30-day money-back guarantee
See the full learning path5
lessons
41
practice questions
27
prerequisite lessons
1 of the 5 lessons here is free to preview - the whole explanation and worked example, with no account and no email.
The editor you get
A still of the editor, not a live one
Python Editor
Editor Output
Output:
10
You write and run Python in the browser - nothing to install, no setup. Questions are marked on the values your code produces. The snippet here is an example of the kind of code you write.
The 5 lessons in this unit. Expand any one to see what it covers. Each unlocks when its own prerequisites are passed.
01
for loops
16 questions
Understand how Python's for loop iterates over elements in sequences such as lists, tuples and strings, and how the range() function can control loop repetition for a specified number of iterations.
Covers
For loop overview
range() function
For loops using range()
Iterating over lists, tuples and strings
02
while loops
4 questions
Understand how to use Python while loops to repeatedly execute code until a specified condition is met, and recognise the importance of updating loop variables to avoid infinite loops.
Covers
While loops
03
Loop control flow
13 questions
Learn how to control loop execution in Python using the continue statement to skip iterations, the break statement to exit early, and the else clause to run code only if the loop completes without a break.
Covers
The continue statement
The break statement
for-else and while-else
04
Nested for loops
4 questions
Learn how a nested for loop executes by having the inner loop complete all its iterations for each run of the outer loop, and use this structure to process complex data like lists of lists.
Covers
Nested for loops
05
Activity: space expedition planner
4 questions
Write Python code to organise a space expedition by generating a task list, tracking supplies, assigning crew tasks, and summarising mission activities.
Covers
Generate task list
Track supply levels
Assign tasks to crew members
Mission activity summary
This unit is part of our Python Done Right learning path, which contains 100 lessons. Every one of them is drawn below.
The diagnostic test lets you skip any lesson you already know, including the ones in this unit.
Hover any dot to name its lesson.
5 lessons in this unit
27 prerequisite lessons across the unit, counting every step back to the start
68 other lessons in the learning path - after this unit, or alongside it
Builds on: Assorted extras, Built-in functions, Lists, Python basics, Tuples
Leads to: Assorted extras, Built-in functions, Dictionaries, Python basics
One subscription covers every learning path, and you can test out of anything you already know.
One subscription covers every learning path · 30-day money-back guarantee
More in Iteration: Sequences, Comprehensions