1. Home
  2. Computer Science MCQs
  3. C Programming
  4. Which C loop structure always executes its body at least…

Added 30 Nov -0001

Which C loop structure always executes its body at least once, even when the controlling condition is false on entry?

  1. The switch statement, which selects a case label
  2. The do-while loop, which tests after the body Correct answer
  3. The while loop, which tests before the body
  4. The for loop, which tests before the body

Correct answer

B. The do-while loop, which tests after the body

17 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs