English

State the difference between WHILE and DO-WHILE with proper syntaх.

Advertisements

Question

State the difference between WHILE and DO-WHILE with proper syntaх.

Distinguish Between
Advertisements

Solution

While

Do-While

1. The while loop is an entry-controlled loop in which the condition is checked before executing the loop body.

1. The do-while loop is an exit-controlled loop in which the condition is checked after executing the loop body.

2. The while loop executes its statements only when the specified condition is true.

2. The do-while loop executes its statements once before checking the specified condition.

3. The while loop may execute zero times if the condition is initially false.

3. The do-while loop executes at least once, even if the condition is initially false.

4. The while loop does not require a semicolon after the closing brace of the loop body.

4. The do-while loop requires a semicolon after the while condition.

5. while (condition) { // Statements to be executed }

5. do { // Statements to be executed } while (condition);

shaalaa.com
  Is there an error in this question or solution?
Chapter 7: Statements and their Scope - EXERCISE [Page 163]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 7 Statements and their Scope
EXERCISE | Q 7. | Page 163
Advertisements
Share
Notifications



      Forgot password?
Use app×