QUESTION IMAGE
Question
you are creating a game in which an enemy sprite performs a certain action five times and then stops. which type of loop would be the best choice for this function?
a. an infinite loop
b. a while loop
c. a repeat loop
d. a forever loop
An infinite/forever loop runs indefinitely, so A and D are incorrect. A while loop runs while a condition is true, but for a fixed number of iterations (5 times), a repeat loop (which can execute a block a specified number of times) is more suitable. Wait, actually, in many programming contexts, a "repeat" loop (or "for" loop in some languages, but here the option is repeat) is used for a set number of iterations. Wait, correction: Let's analyze each option. An infinite/forever loop (A, D) runs without stopping, so they're out. A while loop (B) depends on a condition, but we need to run exactly 5 times. A repeat loop (C) can be set to repeat a certain number of times (like repeat 5 times), making it the best choice for executing an action 5 times and then stopping.
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
C. A repeat loop