Correct option is B
The correct answer is
(b) The loop will execute at least once, regardless of the user input. Since this is a do-while loop, it will execute
at least once before checking the condition, even if the user inputs -1 as the first value.
Important Key Points:
1.
Do-While Loop Behavior: A do-while loop
executes its body at least once before evaluating the condition, meaning the user will always be prompted for input once, regardless of the input value.
2. The loop continues as long as number is not equal to -1
and count is less than
5. The loop may end after
5 inputs or earlier if -1 is entered.
Knowledge Booster:
·
Option (a): Incorrect, because in a do-while loop, the body executes
at least once, even if the user inputs -1 initially.
·
Option (c): Incorrect, because the loop may execute
fewer than five times if the user enters -1 early.
·
Option (d): Incorrect, as the loop checks the conditions (number != -1 && count < 5) in each iteration and may terminate before five iterations.
·
Option (e): Incorrect, since the loop is bounded by both
user input (-1) and the
count < 5 condition. Therefore, it will not run indefinitely.