Ask Question
28 June, 07:15

If you need to write a do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the user enters a correct number, what is the loop condition? (2 > number || number > 5) (2 5) (2 < = number && number < = 5)

+4
Answers (1)
  1. 28 June, 07:39
    0
    Answer: (2 > number || number > 5)

    Step-by-step explanation:

    The do-while loop need to work until the user enters a correct number. In this case the number need to be between 2 and 5 inclusive.

    On the opposite, if the user enters a number between 2 and 5 inclusive, he will leave the do-while loop.

    Here is how it works : Once the user enters a number, the do-while loop will check this number.

    If the number is NOT between 2 and 5 inclusive, the do-while loop will ask again the user to enter a number.

    If the number is between 2 and 5 inclusive, the loop stop working.

    So the do-while loop need to check if the number IS NOT between 2 and 5 inclusive.

    If it is not between 2 and 5 inclusive, it could be:

    Smaller than 2 : number < 2

    Or greater than 5 = number > 5

    The "or" condition is written by the symbols "||".

    The loop condition is (2 > number || number > 5).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “If you need to write a do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the ...” in 📘 Mathematics if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers