Cursos /
Python Loops Tutorial
If/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?
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a8aeafab-f546-47e9-adb6-1d97b2927804/2_4_bbjk.gif)
Tarefa
Multiply all the negative numbers in the list.
- Initialize a
while
loop, utilizingi
to interact withnumbers
. - Establish the condition if an element is less than 0.
- Multiply the element and accumulate it in the
counter
. - Update the value of
i
to change the list index. - Display the value stored in the
counter
.
Tudo estava claro?
Seção 2. Capítulo 4
Conteúdo do Curso
Python Loops Tutorial
Python Loops Tutorial
If/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?
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/a8aeafab-f546-47e9-adb6-1d97b2927804/2_4_bbjk.gif)
Tarefa
Multiply all the negative numbers in the list.
- Initialize a
while
loop, utilizingi
to interact withnumbers
. - Establish the condition if an element is less than 0.
- Multiply the element and accumulate it in the
counter
. - Update the value of
i
to change the list index. - Display the value stored in the
counter
.
Tudo estava claro?
Seção 2. Capítulo 4