Course Content
Python Loops Tutorial
Python Loops Tutorial
The First while Loop
Let's proceed!
The while
loop!
The while
statement verifies a condition. The condition should yield a Boolean value, which can be either True
or False
.
If the condition evaluates to True
, the while
statement executes the statements contained within its block.
The while
statement keeps reevaluating the condition with each iteration and continues to execute its block until the condition becomes False
.
Take a look at the code below:
# Setting variable to change numbers i = 0 # Printing numbers from 0 to 9 while i < 10: print(i) i += 1
How does the code work?
Swipe to show code editor
Print numbers from 10 to 0.
- Initialize the
while
loop with the variablei
. - Continuously print the numbers while the loop is active.
- Decrease
i
by1
with each iteration.
Thanks for your feedback!
The First while Loop
Let's proceed!
The while
loop!
The while
statement verifies a condition. The condition should yield a Boolean value, which can be either True
or False
.
If the condition evaluates to True
, the while
statement executes the statements contained within its block.
The while
statement keeps reevaluating the condition with each iteration and continues to execute its block until the condition becomes False
.
Take a look at the code below:
# Setting variable to change numbers i = 0 # Printing numbers from 0 to 9 while i < 10: print(i) i += 1
How does the code work?
Swipe to show code editor
Print numbers from 10 to 0.
- Initialize the
while
loop with the variablei
. - Continuously print the numbers while the loop is active.
- Decrease
i
by1
with each iteration.
Thanks for your feedback!
The First while Loop
Let's proceed!
The while
loop!
The while
statement verifies a condition. The condition should yield a Boolean value, which can be either True
or False
.
If the condition evaluates to True
, the while
statement executes the statements contained within its block.
The while
statement keeps reevaluating the condition with each iteration and continues to execute its block until the condition becomes False
.
Take a look at the code below:
# Setting variable to change numbers i = 0 # Printing numbers from 0 to 9 while i < 10: print(i) i += 1
How does the code work?
Swipe to show code editor
Print numbers from 10 to 0.
- Initialize the
while
loop with the variablei
. - Continuously print the numbers while the loop is active.
- Decrease
i
by1
with each iteration.
Thanks for your feedback!
Let's proceed!
The while
loop!
The while
statement verifies a condition. The condition should yield a Boolean value, which can be either True
or False
.
If the condition evaluates to True
, the while
statement executes the statements contained within its block.
The while
statement keeps reevaluating the condition with each iteration and continues to execute its block until the condition becomes False
.
Take a look at the code below:
# Setting variable to change numbers i = 0 # Printing numbers from 0 to 9 while i < 10: print(i) i += 1
How does the code work?
Swipe to show code editor
Print numbers from 10 to 0.
- Initialize the
while
loop with the variablei
. - Continuously print the numbers while the loop is active.
- Decrease
i
by1
with each iteration.