Exercise: Loops

Questions for: Loops

Which keyword is used to skip the rest of the code in the current iteration of a loop and move to the next iteration?
A:
pass
B:
continue
C:
skip
D:
next
Answer: B
The continue statement is used to skip the rest of the code in the current iteration of a loop and move to the next iteration.
What will be the output of the following code?
for i in range(3):
    print(i)
A:
0
B:
1
C:
2
D:
0 1 2
Answer: D
The range(3) generates values 0, 1, and 2, and the for loop iterates over these values, printing them.
Ad Slot (Above Pagination)
Quiz