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?
Tarea
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
.
¿Todo estuvo claro?
Sección 2. Capítulo 4
Contenido del 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?
Tarea
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
.
¿Todo estuvo claro?
Sección 2. Capítulo 4