Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Infinite Loops | While Loops: Essentials
Python Loops
course content

Зміст курсу

Python Loops

Python Loops

1. While Loops: Get Started
2. While Loops: Essentials
3. For Loops
4. Nested Loops

Infinite Loops

Here is the question: what if the condition always has a constant value of True or False? If it is False, we simply skip the instructions inside the loop's body. But for True, we get the infinite loop: you'll never leave it, and your code can execute without stopping (or until the process will be interrupted). Beginners (and even experienced programmers) sometimes accidentally code the infinite loops due to different reasons.

For example, the following code snippet is an infinite loop because the counter i is constant, probably, the programmer forgot about updating counter i += 1.

123
i = 1 while i < 100: print(i*i)
copy

This loop is infinite because the stop condition is constantly True.

12
while 2 + 2 == 4: print('Math works!')
copy

You should avoid the infinite loops and double check if the condition ever becomes False.

Завдання

Be careful, this loop is infinite. Change the condition so that the loop is finite and list_ contains following values:

1 2 4 8 16 32 64

Завдання

Be careful, this loop is infinite. Change the condition so that the loop is finite and list_ contains following values:

1 2 4 8 16 32 64

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

Все було зрозуміло?

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

Infinite Loops

Here is the question: what if the condition always has a constant value of True or False? If it is False, we simply skip the instructions inside the loop's body. But for True, we get the infinite loop: you'll never leave it, and your code can execute without stopping (or until the process will be interrupted). Beginners (and even experienced programmers) sometimes accidentally code the infinite loops due to different reasons.

For example, the following code snippet is an infinite loop because the counter i is constant, probably, the programmer forgot about updating counter i += 1.

123
i = 1 while i < 100: print(i*i)
copy

This loop is infinite because the stop condition is constantly True.

12
while 2 + 2 == 4: print('Math works!')
copy

You should avoid the infinite loops and double check if the condition ever becomes False.

Завдання

Be careful, this loop is infinite. Change the condition so that the loop is finite and list_ contains following values:

1 2 4 8 16 32 64

Завдання

Be careful, this loop is infinite. Change the condition so that the loop is finite and list_ contains following values:

1 2 4 8 16 32 64

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

Все було зрозуміло?

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

Infinite Loops

Here is the question: what if the condition always has a constant value of True or False? If it is False, we simply skip the instructions inside the loop's body. But for True, we get the infinite loop: you'll never leave it, and your code can execute without stopping (or until the process will be interrupted). Beginners (and even experienced programmers) sometimes accidentally code the infinite loops due to different reasons.

For example, the following code snippet is an infinite loop because the counter i is constant, probably, the programmer forgot about updating counter i += 1.

123
i = 1 while i < 100: print(i*i)
copy

This loop is infinite because the stop condition is constantly True.

12
while 2 + 2 == 4: print('Math works!')
copy

You should avoid the infinite loops and double check if the condition ever becomes False.

Завдання

Be careful, this loop is infinite. Change the condition so that the loop is finite and list_ contains following values:

1 2 4 8 16 32 64

Завдання

Be careful, this loop is infinite. Change the condition so that the loop is finite and list_ contains following values:

1 2 4 8 16 32 64

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

Все було зрозуміло?

Here is the question: what if the condition always has a constant value of True or False? If it is False, we simply skip the instructions inside the loop's body. But for True, we get the infinite loop: you'll never leave it, and your code can execute without stopping (or until the process will be interrupted). Beginners (and even experienced programmers) sometimes accidentally code the infinite loops due to different reasons.

For example, the following code snippet is an infinite loop because the counter i is constant, probably, the programmer forgot about updating counter i += 1.

123
i = 1 while i < 100: print(i*i)
copy

This loop is infinite because the stop condition is constantly True.

12
while 2 + 2 == 4: print('Math works!')
copy

You should avoid the infinite loops and double check if the condition ever becomes False.

Завдання

Be careful, this loop is infinite. Change the condition so that the loop is finite and list_ contains following values:

1 2 4 8 16 32 64

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 2. Розділ 1
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt