do-while loop Statement In C Language

aimtocode

do-while loop statement

In do-while loop, first attempt of loop should be executed then it check the condition.

The benefit of do-while loop/statement is that we get entry in loop and then condition will check for very first time.

In while loop, condition will check first and if condition will not satisfied then the loop will not execute any further.

Syntax:

  • Check the test condition.
  • If it is true, execute the body of the loop.
  • If it is false, execute the next statement.

Flowchart:

Example:



Output:

 Value of j variable is: 0
 Value of j variable is: 1
 Value of j variable is: 2
 Value of j variable is: 3

Difference between while and do-while

do-while while
Condition is checked at the end of the loop. Condition is checked in the beginning of the loop.
Set of statements within the loop will be executed atleast once. If the condition is fals, the statements will not be executed even once.


Read Also:


aimtocode