GK Question

technology medium mcq

Which loop structure guarantees execution of the loop body at least once?

  1. for
  2. while
  3. do-while
  4. foreach

Answer: do-while

do-while loop checks condition AFTER executing the body, ensuring at least one iteration. Syntax: do { ... } while(condition);. Useful for menu-driven programs, input validation where first attempt is always needed. while/for check condition BEFORE execution, potentially skipping body entirely if condition initially false.

Topic Programming Logic
Exam Relevance SSC JE, Railway, Banking