like a while statement, “ do while statement” repeats a set of statements if condition is true.
If condition is false the flow of control do not enter inside the do-while loop.
“do-while” first execute the body of loop than tests the condition.
Means even if the condition if false do-while executes at least ones.
The syntax of a do…while loop in C programming language is −
1 2 3 4 5 6 7 8 | do { Statement1; Statement2; ---- ---- Increment/Decrement; } while( condition ); |
Example: Write a program to print 1 to 10 using while loop.
#includeOUTPUT
1 2 3 4 5 6 7 8 9 10 | 1 2 3 4 5 6 7 8 9 10 |
Even if the condition if false do-while executes at least ones.
#includeOUTPUT
1 | 100 |