Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
while loop (1/2) | Loops
Learn Python from Scratch
course content

Зміст курсу

Learn Python from Scratch

Learn Python from Scratch

1. The basics
2. Arithmetic operations
3. Common data types
4. Conditional statements
5. Other data types
6. Loops
7. Functions

bookwhile loop (1/2)

Sometimes you need your code to run all the time when the condition holds. For example, in real life, we don't quit the metro train till we reach our station. I.e. if we need "Station B" we will miss "Station A", "Station C" and so on, until we reach "Station B". In Python you can write something like this using while loop:

12
while condition: do
copy

For example, we can print all the numbers to 10.

1234567
# assign starting number i = 1 # while loop will print all the numbers to 10 while i < 10: # condition print(i) # action i = i + 1 # increasing variable
copy

You might notice, that we use i = i + 1 inside the loop. If we didn't specify that, our loop would be infinite, as every time it checked condition it got 1 < 10, which is True. Be careful while using this type of loop in order not to make your code execution infinite.

Завдання

  1. Create variable i with value 1.
  2. Using while loop print all the numbers less than 10 squared. Do not forget to increase your number on each step!

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 6. Розділ 1
toggle bottom row

bookwhile loop (1/2)

Sometimes you need your code to run all the time when the condition holds. For example, in real life, we don't quit the metro train till we reach our station. I.e. if we need "Station B" we will miss "Station A", "Station C" and so on, until we reach "Station B". In Python you can write something like this using while loop:

12
while condition: do
copy

For example, we can print all the numbers to 10.

1234567
# assign starting number i = 1 # while loop will print all the numbers to 10 while i < 10: # condition print(i) # action i = i + 1 # increasing variable
copy

You might notice, that we use i = i + 1 inside the loop. If we didn't specify that, our loop would be infinite, as every time it checked condition it got 1 < 10, which is True. Be careful while using this type of loop in order not to make your code execution infinite.

Завдання

  1. Create variable i with value 1.
  2. Using while loop print all the numbers less than 10 squared. Do not forget to increase your number on each step!

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 6. Розділ 1
toggle bottom row

bookwhile loop (1/2)

Sometimes you need your code to run all the time when the condition holds. For example, in real life, we don't quit the metro train till we reach our station. I.e. if we need "Station B" we will miss "Station A", "Station C" and so on, until we reach "Station B". In Python you can write something like this using while loop:

12
while condition: do
copy

For example, we can print all the numbers to 10.

1234567
# assign starting number i = 1 # while loop will print all the numbers to 10 while i < 10: # condition print(i) # action i = i + 1 # increasing variable
copy

You might notice, that we use i = i + 1 inside the loop. If we didn't specify that, our loop would be infinite, as every time it checked condition it got 1 < 10, which is True. Be careful while using this type of loop in order not to make your code execution infinite.

Завдання

  1. Create variable i with value 1.
  2. Using while loop print all the numbers less than 10 squared. Do not forget to increase your number on each step!

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Sometimes you need your code to run all the time when the condition holds. For example, in real life, we don't quit the metro train till we reach our station. I.e. if we need "Station B" we will miss "Station A", "Station C" and so on, until we reach "Station B". In Python you can write something like this using while loop:

12
while condition: do
copy

For example, we can print all the numbers to 10.

1234567
# assign starting number i = 1 # while loop will print all the numbers to 10 while i < 10: # condition print(i) # action i = i + 1 # increasing variable
copy

You might notice, that we use i = i + 1 inside the loop. If we didn't specify that, our loop would be infinite, as every time it checked condition it got 1 < 10, which is True. Be careful while using this type of loop in order not to make your code execution infinite.

Завдання

  1. Create variable i with value 1.
  2. Using while loop print all the numbers less than 10 squared. Do not forget to increase your number on each step!

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 6. Розділ 1
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
some-alt