ICSE Class 10 Computer Applications
Question 36 of 76
Revising Basic Java Concepts — Question 40
Back to all questions 40
Question Question 21
What is the difference between a while and do-while loop ?
| while loop | do-while loop |
|---|---|
| while is an entry-controlled loop. | do-while is an exit-controlled loop. |
| while loop checks the test condition at the beginning of the loop. | do-while loop checks the test condition at the end of the loop. |
| while loop executes only if the test condition is true. | do-while loop executes at least once, even if the test condition is false. |
| while loop is helpful in situations where number of iterations is not known. | do-while loop is suitable when we need to display a menu to the user. |
| Syntax: while(test condition) { ... } | Syntax: do { ... }while(condition); |