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

Course Content

Python Loops Tutorial

Python Loops Tutorial

1. The for Loop
2. The while Loop
3. Nested Loops

bookThe 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:

1234567
# Setting variable to change numbers i = 0 # Printing numbers from 0 to 9 while i < 10: print(i) i += 1
copy

How does the code work?

Task
test

Swipe to show code editor

Print numbers from 10 to 0.

  1. Initialize the while loop with the variable i.
  2. Continuously print the numbers while the loop is active.
  3. Decrease i by 1 with each iteration.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 1
toggle bottom row

bookThe 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:

1234567
# Setting variable to change numbers i = 0 # Printing numbers from 0 to 9 while i < 10: print(i) i += 1
copy

How does the code work?

Task
test

Swipe to show code editor

Print numbers from 10 to 0.

  1. Initialize the while loop with the variable i.
  2. Continuously print the numbers while the loop is active.
  3. Decrease i by 1 with each iteration.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 1
toggle bottom row

bookThe 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:

1234567
# Setting variable to change numbers i = 0 # Printing numbers from 0 to 9 while i < 10: print(i) i += 1
copy

How does the code work?

Task
test

Swipe to show code editor

Print numbers from 10 to 0.

  1. Initialize the while loop with the variable i.
  2. Continuously print the numbers while the loop is active.
  3. Decrease i by 1 with each iteration.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

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:

1234567
# Setting variable to change numbers i = 0 # Printing numbers from 0 to 9 while i < 10: print(i) i += 1
copy

How does the code work?

Task
test

Swipe to show code editor

Print numbers from 10 to 0.

  1. Initialize the while loop with the variable i.
  2. Continuously print the numbers while the loop is active.
  3. Decrease i by 1 with each iteration.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Section 2. Chapter 1
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt