
control statements
Quiz
•
Computers
•
University
•
Practice Problem
•
Hard
thanga_palani_ thanga_palani_
FREE Resource
Enhance your content in a minute
13 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the break statement do in a loop?
Restarts the loop
Skips the current step
Exits the loop completely
Makes the loop run forever
Answer explanation
The break statement is used in loops to exit the loop completely, terminating its execution. This means that when a break is encountered, the loop stops running, and control is transferred to the statement following the loop.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the continue statement do?
Ends the loop
Skips the rest of the loop and moves to next iteration
Skips the rest of the loop and moves to next iteration
Skips input
Answer explanation
The continue statement skips the rest of the current loop iteration and proceeds to the next iteration. This means any code after the continue statement within the loop will not execute for that iteration.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will this code output?
for i in range(5):
if i == 3:
break
print(i)
0 1 2
0 1 2 3 4
1 2 3
0 1 2 3
Answer explanation
The loop iterates from 0 to 4. When i is 3, the 'break' statement exits the loop. Thus, only 0, 1, and 2 are printed before the loop is terminated. Therefore, the output is '0 1 2', making it the correct choice.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output?
for i in range(5):
if i == 3:
continue
print(i)
0 1 2 3 4
1 2 3
0 1 2 4
0 1 2
Answer explanation
The loop iterates from 0 to 4. When i is 3, the 'continue' statement skips the print. Thus, the output is 0, 1, 2, and 4, making the correct answer '0 1 2 4'.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
In a while loop, where is break used?
Inside a condition
Inside the loop block
Outside the loop
After loop ends
Answer explanation
The 'break' statement is used inside the loop block to exit the loop prematurely when a specific condition is met. This allows for more control over the loop's execution, making 'Inside the loop block' the correct choice.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What happens if break is not used?
Loop stops
Loop continues normally
Syntax error
System shuts down
Answer explanation
If 'break' is not used in a loop, the loop continues normally, executing all iterations until its condition is no longer met. This means the loop will run to completion unless interrupted by other means.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does this print?
i = 0 while i < 5:
i += 1
if i == 3:
continue
print(i)
1 2 3 4 5
1 2 4 5
1 2 3 5
0 1 2 3
Answer explanation
The loop increments i from 0 to 5. When i equals 3, the 'continue' statement skips the print, so 3 is not printed. The output is 1, 2, 4, and 5, making '1 2 4 5' the correct answer.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
12 questions
ロジックテスト (Đề kiểm tra năng lực IT)
Quiz
•
University
10 questions
Python with DataScience
Quiz
•
7th Grade - University
17 questions
Archivos
Quiz
•
University
12 questions
Cloud Computing - Introducción
Quiz
•
University
10 questions
Post Test #4 - Python Fundamental #3
Quiz
•
University
16 questions
Meet ACM
Quiz
•
University
13 questions
Digital Technology Office 365 - 29May2020
Quiz
•
University - Professi...
15 questions
GIS Unit III
Quiz
•
University
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
