Conteúdo do Curso
Python Loops Tutorial
Python Loops Tutorial
Nested while Loop
To summarize, the while
loop statement executes a code block repeatedly as long as a specific condition remains True
. We opt for a while
loop when the number of iterations isn't predetermined.
Now, let's delve into employing a while
loop within another while
loop.
Examine the code below:
How does the code work?
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/3_3_1_hjhbj.gif)
In the previous section, we worked with a matrix. We can achieve the same using a nested while
loop!
Examine the code below:
How does the code work?
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/3_3_2_nkm%2C.gif)
Tarefa
Increment every element in the matrix by 1
.
- Configure the outer
while
loop to iterate through each row in the matrix. - Configure the inner
while
loop to iterate through each element in the row of the matrix. - Add
1
to every element. - Display each updated element.
Tudo estava claro?
Conteúdo do Curso
Python Loops Tutorial
Python Loops Tutorial
Nested while Loop
To summarize, the while
loop statement executes a code block repeatedly as long as a specific condition remains True
. We opt for a while
loop when the number of iterations isn't predetermined.
Now, let's delve into employing a while
loop within another while
loop.
Examine the code below:
How does the code work?
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/3_3_1_hjhbj.gif)
In the previous section, we worked with a matrix. We can achieve the same using a nested while
loop!
Examine the code below:
How does the code work?
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/3_3_2_nkm%2C.gif)
Tarefa
Increment every element in the matrix by 1
.
- Configure the outer
while
loop to iterate through each row in the matrix. - Configure the inner
while
loop to iterate through each element in the row of the matrix. - Add
1
to every element. - Display each updated element.
Tudo estava claro?