Which C loop structure always executes its body at least once, even when the controlling condition is false on entry?
Correct answer
B. The do-while loop, which tests after the body
17 views
B. The do-while loop, which tests after the body
17 views
A do-while loop places its condition at the bottom, so the body runs first and the test decides only whether to repeat. The while and for loops are pre-tested and can run zero times, which is why they are preferred when the input may already be exhausted. The do-while form is idiomatic for menu-driven programs and for input loops that must read at least one record.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is B? Ask here and get an explanation.