QUESTION IMAGE
Question
question: 5 you need to write a program that has karel take all the tennis balls where karel is standing if there are any there. karel should end up with no tennis balls on that spot. which control structure do you need to use? for loop while loop if statement if/else statement none of these
A while loop is used when the number of iterations is not known in advance. In this case, we don't know how many tennis - balls are at the spot where Karel is standing. We need to keep taking balls as long as there are balls present. A for - loop is used when the number of iterations is fixed. An if statement just checks a condition and executes a block if true, and an if/else statement checks a condition and executes one block if true and another if false. Here, we need to repeat an action (taking balls) until a condition (no more balls) is met, so a while loop is appropriate.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
B. While Loop