149k views
1 vote
The do-while repetition statement tests the condition _________ the body of the loop executes.

A) Before
B) While
C) After
D) None of the above.

User Swetabh
by
7.1k points

1 Answer

1 vote

Final answer:

The do-while loop tests the condition after the body has executed, ensuring that the loop's body runs at least once regardless of the condition.

Step-by-step explanation:

The do-while repetition statement tests the condition after the body of the loop executes. This means that the loop will always execute at least once before the condition is tested, in contrast to the while loop, which tests the condition before the loop runs. In the context of a do-while loop, you can think of a person standing up from a seated position where the action (standing up) occurs before checking the condition (if they need to stand). Similarly, a car accelerating while driving is akin to the loop's body executing (accelerating) before checking a condition (should the car keep accelerating or stop).

User VdMandele
by
8.2k points