Course Content
Python Loops Tutorial
Python Loops Tutorial
Nested while Loop
To recap, the while
loop statement repeatedly executes a code block while a particular condition is True
. We use a while
loop when the number iteration is not fixed.
We will learn how to use a while
loop inside another while
loop.
Look at the code below:
How does the code work?

In the last section, we worked with a matrix. We can do the same using a nested while
loop!
Look at the code below:
How does the code work?

Task
Add 1
to every element of the matrix.
- Set the outer
while
loop to work with every row in the matrix. - Set the inner
while
loop to work with every element of the row in the matrix. - Add
1
to every element. - Print every updated element.
Everything was clear?
Section 3. Chapter 3