Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

question 4 you need to write a program that has karel take all the tenn…

Question

question 4
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 them

Explanation:

Brief Explanations

Karel needs to keep taking tennis balls as long as there are balls at the spot. A While loop is appropriate as it will continue executing the block of code (taking balls) as long as a certain condition (presence of balls) is true. A For loop is used when you know the exact number of iterations in advance, which is not the case here. If and If/Else statements are for conditional execution based on a single - time check, not for repeated actions until a condition changes.

Answer:

B. While Loop