Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
What does the break statement do in a loop?
Think about what happens when a certain condition is met.
What would be printed by the following code?
for i in range(3):
if i == 1:
continue
print(i)Which number is skipped?
What does the break statement do in a loop?
Think about 'breaking out' of something.
Using 'continue', what will be printed by this code?
for i in range(4):
if i == 1:
continue
print(i)Which number won't show up in the output?
Write a function that utilizes 'break', 'continue', and 'pass' statements to filter out all odd numbers from a given list and return a new list of even numbers.
Think about how you'd use 'continue' to skip odd numbers and 'pass' to ignore zeros.
Create a guessing game where the game continues until the user correctly guesses a given number, using 'break' to exit the loop, 'continue' to skip invalid guesses, and 'pass' for any additional logic you might want to implement later.
Remember to handle invalid inputs with 'continue' and ensure 'break' is reached when the guess is correct.
7 more questions in this section. Enroll free to practise them all.
Enroll free