A game loop runs while lives > 0. Which line lets it end?
- The line that prints the score
- The line that sets lives to 3 before the loop
- The line inside the loop that takes a life away
A quiz must keep asking one question until the answer is right. Which loop fits?
- A while loop on the answer being wrong
- A for loop that always gives exactly ten tries
- No loop, just one if statement
If nothing inside the loop can change the condition, it runs forever.
Circle one: True False
Read sensor data until it reports ready. The wait length is unknown. Which fits?
- A for loop over a fixed range
- A single if statement that checks ready once
- A while loop on the ready signal
Print every name in a class list of known size. Which loop fits and why?
- For, since the list size is known
- While, since names are strings
- While, since lists always need conditions
A while loop counts down but never stops. What is the likely fault?
- The counter starts at zero instead of ten
- The body never updates the counter
- The loop prints too much text
A student waits for a password with a for loop over a huge fixed range, hoping it is enough. Why is while better?
- While waits exactly as long as needed instead of guessing a cap
- For loops cannot check passwords
- While runs faster on each pass
n starts at 4. While n is above 0, the loop prints n then sets n to n minus 1. How many prints?