Using Do-While Repetition Statement


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.


#include<stdio.h>


int main(void)


{

    int x = 1;

    do{

printf("%d", x);

 if(x==1000){


     break;
}

} while(x <=10000);

       

        

        

    }

    printf("\nBroke out of loop at x==%d\n", x);


    return 0;

}

Comments

Popular posts from this blog

Body Mass Index Calculator In C

Adding two Integers in Java Application

Calculating Product, sum, difference, and quotient of Five Integers