do while loop statement allows you to execute code block in loop body at least one. Here is do while loop syntax:
1 | do { |
2 | // statements |
3 | } while (expression); |
Here is an example of using do while loop statement:
01 | #include <stdio.h> |
02 | void main(){ |
03 | int x = 5; |
04 | int i = 0; |
05 | // using do while loop statement |
06 | do { |
07 | i++; |
08 | printf ( "%d\n" ,i); |
09 | } while (i < x); |
10 | |
11 | } |
The program above print exactly 5 times as indicated in do while loop body
1
2
3
4
5
0 comments:
Post a Comment