18.7k views
4 votes
What does this program print?

for i in range(10):
if i == 3:
continue
print(i)

1 Answer

7 votes

Final answer:

The Python program will print numbers from 0 to 9, excluding 3, because the 'continue' statement causes the loop to skip printing the number 3.

Step-by-step explanation:

The question asks what will be printed by a Python for loop that contains a conditional statement with a continue keyword. The loop iterates over a range of numbers from 0 to 9. When the variable i is equal to 3, the continue statement is executed, which causes the loop to immediately skip the remaining code inside the loop for that iteration and move on to the next iteration. Therefore, the number 3 will not be printed. Instead, the program will print all numbers from 0 to 9, excluding 3.

The output of this program will be:

0
1
2
4
5
6
7
8
9
User Wai Han Ko
by
8.5k points