
control statements

Quiz
•
Computers
•
University
•
Hard
thanga_palani_ thanga_palani_
FREE Resource
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.
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
Session 2 | U

Quiz
•
University
15 questions
Exam 1 Practice

Quiz
•
University
15 questions
Week 7 Quiz

Quiz
•
University
16 questions
Python Basics

Quiz
•
KG - University
14 questions
Scratch Basics Term 3 Final

Quiz
•
KG - University
10 questions
Array in C

Quiz
•
University
15 questions
PROGRAMMING IN PYTHON - UNIT II - TEST 1 MCQS

Quiz
•
University
11 questions
ACM AI Pytorch Review

Quiz
•
University
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
10 questions
UPDATED FOREST Kindness 9-22

Lesson
•
9th - 12th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
20 questions
US Constitution Quiz

Quiz
•
11th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
10 questions
Would you rather...

Quiz
•
KG - University
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
10 questions
The Constitution, the Articles, and Federalism Crash Course US History

Interactive video
•
11th Grade - University
7 questions
Figurative Language: Idioms, Similes, and Metaphors

Interactive video
•
4th Grade - University
20 questions
Levels of Measurements

Quiz
•
11th Grade - University
16 questions
Water Modeling Activity

Lesson
•
11th Grade - University
10 questions
ACT English prep

Quiz
•
9th Grade - University