Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
If/Else in a while Loop | The while Loop
course content

Зміст курсу

Python Loops Tutorial

If/Else in a while LoopIf/Else in a while Loop

We previously used the if/else structure in conjunction with for loops, and we can apply the same concept to while loops.

An if/else structure within a while loop functions when the while condition becomes False.

Examine the code below:

How does the code work?

Завдання

Multiply all the negative numbers in the list.

  1. Initialize a while loop, utilizing i to interact with numbers.
  2. Establish the condition if an element is less than 0.
  3. Multiply the element and accumulate it in the counter.
  4. Update the value of i to change the list index.
  5. Display the value stored in the counter.

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

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

Зміст курсу

Python Loops Tutorial

If/Else in a while LoopIf/Else in a while Loop

We previously used the if/else structure in conjunction with for loops, and we can apply the same concept to while loops.

An if/else structure within a while loop functions when the while condition becomes False.

Examine the code below:

How does the code work?

Завдання

Multiply all the negative numbers in the list.

  1. Initialize a while loop, utilizing i to interact with numbers.
  2. Establish the condition if an element is less than 0.
  3. Multiply the element and accumulate it in the counter.
  4. Update the value of i to change the list index.
  5. Display the value stored in the counter.

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

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