Nested loop
A nested loop is a loop placed inside another loop so that the inner loop executes within each iteration of the outer loop.
Get Programming: Learn to code with Python
A nested loop is a loop placed inside another loop so that its execution occurs within each iteration of the outer loop.
- How it is used
- Uses nested loops to test every letter of each candidate word against available Scrabble tiles.
- How deep it goes
- Explains outer and inner responsibilities, early exit, duplicate handling, remaining state, and the final completion check.
- Examples
- Demonstrates word candidates, individual letters, tile removal, duplicate letters, and words such as art, hue, and color.
- What you can do after
- Build it from scratch by translating a two-level checking process into pseudocode and executable loop logic.
Read how Get Programming: Learn to code with Python explains nested loop →
Learn AI-Assisted Python Programming, Second Edition
A nested loop is a loop whose body contains another loop, causing the inner loop to complete its iterations for each iteration of the outer loop.
- How it is used
- Processes every combination or every cell in row-and-column data.
- How deep it goes
- Explains execution order and list-of-lists traversal, but stops short of performance analysis.
- Examples
- Uses country pairs and an Olympic-medals list to demonstrate nested iteration.
- What you can do after
- Apply nested Python for loops to generate combinations and visit two-dimensional list values.
Read how Learn AI-Assisted Python Programming, Second Edition explains nested loop →
Practices of the Python Pro
A nested loop is a loop construct placed inside the body of another loop, causing repeated iteration across multiple levels.
- How it is used
- Uses nested loops to identify quadratic growth while analyzing algorithm performance.
- How deep it goes
- Explains the repeated comparisons, early termination, and worst-case O(n²) behavior without extending into optimization techniques.
- Examples
- Demonstrates duplicate detection with Python loops over a sequence.
- What you can do after
- Evaluate nested-loop code by recognizing its potential quadratic worst-case running time.
Related concepts
- loopkind of · A loop is a programming control-flow construct that repeatedly executes a block of instructions according to an iteration rule or continuation condition.
- matrix-matrix multiplicationuses · Matrix multiplication combines compatible matrices to form a result whose entries are sums of products between rows of the first matrix and columns of the second.
- GPU kernelalternative to · A GPU kernel is an executable program or function that performs computation on a graphics processing unit, commonly using parallel threads.
- Cartesian productequivalent to · A Cartesian product is the set of all ordered tuples formed by selecting one element from each of multiple sets or sequences.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


