A loop that repeats until a condition is met, rather than a set number of times
What is the name for a Boolean variable used to record whether something has happened, such as whether a loop should stop?
Flag
What is meant by a while loop?
A loop that checks its condition before each pass, so its body may run zero times
Which term describes a loop that runs forever because nothing inside it changes the value used in its condition?
Infinite loop
What is meant by a running total?
A variable that has each new value added to it, so it holds the sum of the values so far
What is the name for the variable a programmer sets before a loop and changes inside it to keep track of how many times the loop has run?
Counter
In Python, how does the computer know which lines make up the body of a while loop?
The lines indented under the while statement
What is meant by the condition of a while loop?
A Boolean expression that is either True or False
When is a condition-controlled loop the right choice instead of a count-controlled loop?
When the number of repeats is not known in advance
How many times does the body of this loop run?
Zero times
count starts at 1. The loop while count is less than or equal to 10: adds 1 to count on each pass. What is the value of count when the loop ends?
11
A loop starts with count = 1 and uses the condition while count is less than or equal to 10:, but the loop never ends. What is the cause?
Count is never given a new value inside the loop
A loop must always run its body at least once before an answer can be checked. When is the condition checked in this loop?
At the end of each pass
A loop begins with finished = False and while not finished:. The body asks the user for an answer. Which line at the end of the body sets the flag so the loop stops only when the answer is correct?
Finished = answer == 'Correct'
A guessing game uses the loop while guess != secret and attempts < 3:. When does this loop stop?
When the guess is right or three attempts have been used
A loop adds each number entered to a total and stops when 0 is entered. The user enters 5, 8, 3, then 0. What total is displayed?
Total: 16
In a loop that adds numbers until 0 is entered, the first input is read before the loop starts. Why is this done?
So the condition has a value to test
A loop uses while guess != secret or attempts < 3:. When does this loop stop?
When the guess is right and three attempts have been used
Two loops both keep asking for a guess until it is correct. One checks its condition before each pass, the other is set up to run at least once. The first guess is correct. What is the difference between the two loops?
The first loop skips its body, the second runs its body once
In a number guessing game, guess is set to 0 before the loop while guess != secret: runs. Why is this done?
So the condition is True at the first check and the body runs
A program uses while True: on purpose, so that it keeps running until the user closes it. Which statement about this loop is correct?
It repeats forever on purpose, so it is not a logic error
We use cookies to enhance your experience. You can manage your preferences or learn more in our Cookie Policy.