An hourglass symbol should appear on the screen until an image loads. What kind of structure will this require?

sequence
selection
condition controlled loop
count controlled looop

1 answer

To display an hourglass symbol on the screen while an image is loading, you would typically use a condition-controlled loop.

Here's a brief explanation of the options:

  • Sequence: This refers to executing statements in a linear order, one after the other. It does not suit the loading scenario as it doesn't allow for repeated checks or updates while the image loads.

  • Selection: This structure involves decision-making, such as if-else statements. Although it could be part of the code, it doesn't serve the ongoing check needed during loading.

  • Condition-Controlled Loop: This loop continues to execute as long as a specific condition is true. In this case, the condition would be whether the image has finished loading or not. Thus, while waiting for the image to load, you can keep displaying the hourglass.

  • Count-Controlled Loop: This type of loop runs a specific number of times regardless of a condition. It is not suitable for waiting on an event like loading an image because you typically do not know beforehand how many iterations will be needed.

Therefore, the best fit for this scenario is a condition-controlled loop.