Machine-translated by Google. Questions are authored in English.
Top

Discussion

A do-while loop always executes its loop body at least ..................

  • A.twice
  • B.three times
  • C.once
  • D.four times

Answer: C

A do-while loop executes its body at least once.

In do { ... } while (condition); the condition is tested after the body has run. So the body runs once before the condition is ever checked, even if the condition is false from the start. A while loop tests first and may execute zero times, which is the key difference between the two.

Nothing in the construct forces a second, third or fourth pass: if the condition is false after the first pass, the loop ends.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.