Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Nested while Loop | Nested Loops
Python Loops Tutorial

Nested while LoopNested 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?

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?

Завдання

Increment every element in the matrix by 1.

  1. Configure the outer while loop to iterate through each row in the matrix.
  2. Configure the inner while loop to iterate through each element in the row of the matrix.
  3. Add 1 to every element.
  4. Display each updated element.

Все було зрозуміло?

Секція 3. Розділ 3
toggle bottom row
course content

Зміст курсу

Python Loops Tutorial

Nested while LoopNested 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?

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?

Завдання

Increment every element in the matrix by 1.

  1. Configure the outer while loop to iterate through each row in the matrix.
  2. Configure the inner while loop to iterate through each element in the row of the matrix.
  3. Add 1 to every element.
  4. Display each updated element.

Все було зрозуміло?

Секція 3. Розділ 3
toggle bottom row
some-alt