Using Do-While Repetition Statement
A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block.
this tutorial shows us how to use a do while repetition statement to break out loop.
Now lets assume you are printing loads of data using this do while loop and you want it to stop at a particular point of mark, that is where the break statements comes in. The break statement are used to alter the flow of control, the break statement when executed in a do-while statement causes an immediate exit from that statement. The program below illustrates how to use the do-while statement.
Now lets assume you are printing loads of data using this do while loop and you want it to stop at a particular point of mark, that is where the break statements comes in. The break statement are used to alter the flow of control, the break statement when executed in a do-while statement causes an immediate exit from that statement. The program below illustrates how to use the do-while statement.
#include<stdio.h>
int main(void)
{
int x = 1;
do{
printf("%d", x);
} while(x <=10000);
printf("%d", x);
if(x==1000){
break;
}} while(x <=10000);
}
printf("\nBroke out of loop at x==%d\n", x);
return 0;
}
Comments
Post a Comment
Please feel free to comments if you have any ideas, questions and subjection concerning our post and programs