Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
If/Else in a for Loop | The for Loop
course content

Зміст курсу

Python Loops Tutorial

If/Else in a for LoopIf/Else in a for Loop

In the future, you'll frequently encounter and use the if/else construct within loops. Here's a quick reminder of how it works:

  • if - In this part, you specify the condition to check;
  • else - The actions to execute if the condition in the if statement evaluates to False.

Look at the code below:

How does the code work?

Завдання

To create a program that determines whether a number in the list is less than 10, follow these steps:

  1. Configure the for loop to operate on the numbers, using i as an element of the list.
  2. Set the condition i < 10 to check if the number is less than 10.
  3. Display the appropriate messages: 'is lower than 10' if an element is lower than 10 (inside the if block), and 'is greater or equal to 10' if an element is greater than or equal to 10 (inside the else block).

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

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

Зміст курсу

Python Loops Tutorial

If/Else in a for LoopIf/Else in a for Loop

In the future, you'll frequently encounter and use the if/else construct within loops. Here's a quick reminder of how it works:

  • if - In this part, you specify the condition to check;
  • else - The actions to execute if the condition in the if statement evaluates to False.

Look at the code below:

How does the code work?

Завдання

To create a program that determines whether a number in the list is less than 10, follow these steps:

  1. Configure the for loop to operate on the numbers, using i as an element of the list.
  2. Set the condition i < 10 to check if the number is less than 10.
  3. Display the appropriate messages: 'is lower than 10' if an element is lower than 10 (inside the if block), and 'is greater or equal to 10' if an element is greater than or equal to 10 (inside the else block).

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

Секція 1. Розділ 5
toggle bottom row
some-alt