
while loop
Quiz
•
Computers
•
University
•
Practice Problem
•
Hard
thanga_palani_ thanga_palani_
Used 1+ times
FREE Resource
Enhance your content in a minute
15 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does a while loop do?
Runs code once
Runs code until a condition becomes False
Runs only with numbers
Runs forever
Answer explanation
A while loop repeatedly executes a block of code as long as a specified condition remains true. It stops running when the condition evaluates to false, making 'Runs code until a condition becomes False' the correct choice.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the output of this code?
i = 1
while i <= 3:
print(i) i += 1
1 1 1
1 2 3
1 2 3 4
Error
Answer explanation
The code initializes i to 1 and enters a while loop that runs as long as i is less than or equal to 3. It prints the value of i and increments it by 1 each time. The output is 1, 2, 3, which corresponds to the correct choice.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What happens if the condition in while is always True?
Runs once
Infinite loop
Skips the loop
Gives error
Answer explanation
If the condition in a while loop is always true, the loop will continue to execute indefinitely, resulting in an infinite loop. This means the program will not exit the loop unless interrupted or terminated.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of these can cause an infinite loop?
Missing print()
No indentation
No i += 1
Using if
Answer explanation
The correct choice is 'No i += 1'. Without this increment, the loop variable 'i' never changes, causing the loop to run indefinitely. The other options do not directly lead to an infinite loop.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How many times will this loop run?
i = 1
while i < 5:
i += 1
4
5
0
Infinite
Answer explanation
The loop starts with i = 1 and runs while i < 5. It increments i by 1 each time. The values of i will be 1, 2, 3, 4, and then it stops when i becomes 5. Thus, the loop runs 4 times, making the correct answer 4.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does this program do?
x = 1
while x <= 5:
print("Hi")
x += 1
Prints Hi 4 times
Prints Hi 5 times
Runs forever
Gives error
Answer explanation
The program initializes x to 1 and enters a loop that runs while x is less than or equal to 5. It prints 'Hi' and increments x by 1 each time, resulting in 'Hi' being printed 5 times before the loop ends.
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which keyword is used to exit a while loop early?
stop
exit
break
return
Answer explanation
The keyword 'break' is used to exit a while loop early. It immediately terminates the loop, allowing the program to continue with the next statement following the loop. Other options like 'stop' and 'exit' are not valid in this context.
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
10 questions
6-文件操作
Quiz
•
University
13 questions
8 - Организация работы в AutoCAD
Quiz
•
University
12 questions
ASK Tingkatan 1: 2.2.2 Format Imej pada Fail yang Sama
Quiz
•
12th Grade - University
10 questions
Listen in Python
Quiz
•
University
18 questions
WINDOWS 2 ՊԱՏՈՒՀԱՆՆԵՐ
Quiz
•
University
20 questions
C - Structures
Quiz
•
University
17 questions
Email Lớp 6
Quiz
•
6th Grade - University
10 questions
CHAPTER 1: COMPUTER SECURITY REVIEW
Quiz
•
University
Popular Resources on Wayground
5 questions
This is not a...winter edition (Drawing game)
Quiz
•
1st - 5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
10 questions
Identify Iconic Christmas Movie Scenes
Interactive video
•
6th - 10th Grade
20 questions
Christmas Trivia
Quiz
•
6th - 8th Grade
18 questions
Kids Christmas Trivia
Quiz
•
KG - 5th Grade
11 questions
How well do you know your Christmas Characters?
Lesson
•
3rd Grade
14 questions
Christmas Trivia
Quiz
•
5th Grade
20 questions
How the Grinch Stole Christmas
Quiz
•
5th Grade
Discover more resources for Computers
26 questions
Christmas Movie Trivia
Lesson
•
8th Grade - Professio...
20 questions
christmas songs
Quiz
•
KG - University
20 questions
Holiday Trivia
Quiz
•
9th Grade - University
15 questions
Holiday Movies
Quiz
•
University
14 questions
Christmas Trivia
Quiz
•
3rd Grade - University
20 questions
Christmas Trivia
Quiz
•
University
8 questions
5th, Unit 4, Lesson 8
Lesson
•
KG - Professional Dev...
20 questions
Disney Trivia
Quiz
•
University
