Which control structure supports prompting the user for a riddle answer until the correct answer is provided?

Study for the Scripting and Programming Foundations Test. Use curated quizzes and multiple choice questions, each with hints and explanations, to prepare for your exam. Enhance your coding skills and foundational understanding.

The do-while loop is particularly well-suited for scenarios where user interaction is needed, such as prompting for a riddle answer. This control structure allows the code block to execute at least once before checking the condition. When employing a do-while loop to prompt the user, the process starts with asking for the answer, processing it, and then evaluating whether it is correct. If the answer is incorrect, the loop continues to prompt the user again. This ensures that the user is asked repeatedly until the correct answer is provided.

In contrast, a while loop also allows for repeated execution based on a condition but does not guarantee that the loop body will execute at least once, which may not be ideal for prompting user input. A for loop iterates a specific number of times based on a counter and isn't flexible for this type of indefinite user interaction. The if-else branch evaluates a condition but does not inherently support repetition, making it unsuitable for continuously prompting the user until the correct answer is given. Thus, the do-while loop's structure and functionality align perfectly with the requirement to prompt until the correct input is received.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy