While loop is a a pre-test loop, it first test a special conditional expression and as long as conditional expression is true , loop body statement will be executed.
Step 1: In the execution flow, first initialized the value.
Step 2: After initialized the value it checked the condition. If the condition is true then the block of code executed. Then it increments or decrement the value of initialized variable.
Step 3: Repeat step 2 until the condition is false.
Step 4: If the condition is false then stop the execution of statement and it executed outside of the loop.
int i = 0;
while ( i <=10 )
Printf(“%d “,i );
Output: 0 1 2 3 4 5 6 7 8 9 10
For loop is used when we don’t know the number of iterations. Using while loops, we do not need to write the same code again and again.
AUTHOR-SOURAV PURKAITDisclaimer: The author(s) of this blog are solely responsible for the content posted. The blog platform serves as a medium for their expression, and the platform administrators assume no liability for the accuracy or legality of the content.