do {
// statement;
} while (expression);
The statement body is executed at least once. At the end of each iteration, the expression is evaluated. If false (or 0), the loop terminates. If true (or non-zero), the statement body executes another iteration.
Like any other loop structure, a do loop can be terminated by a break or return statement within the statement body. If a continue statement is encountered within the statement body, execution passes to the while clause where expression is re-evaluated.
To understand how a do loop differs from a while loop, compare the following:
int x;
x = 0;
do {
printf ("%d ", ++x);
} while (x<10);
printf ("\n");
x = 0; while (x<10) {
printf ("%d ", ++x);
};
printf ("\n");
Output:
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9
Note that the while loop does not print the value 10. This is because the control expression (x<10) is evaluated before each iteration begins. In a do loop, it is evaluated after each iteration has finished.
No, why did you think so?
yes
567
The do while loop is also called an exit condition loop in c, c++, and java.
yes
int main (int argc, char **argv) { int i=0; do printf ("%2d. %s\n", i, argv[i]); while (++i<argc); return 0; }
In short, a for loop declares an variable and assigns it a value, has an argument, and has an update. A while loop only has an argument. More Detail... in C++, which is very close to C an example while loop is; while(i
A while statement is one type of looping statement. by which we can start a loop in our programs. while loop is precondition checking statement, because it first check its condition then loop will go to its body part. EX. while(i>0) { //body part } here when i will >0 then it will check it body part and execute it and display result.
In C a structure within a structure is called nested. For example, you can embed a while loop in another while loop or for loop in a for loop or an if statement in another if statement.
Available.
usable
the counter variable cannot be initialized in while loop before entering into the block.