+ 1
What is the difference between do{}while () loop and while() loop in C programming?
5 Respuestas
+ 10
Binyaminu Zakariya Please,
Try to read the COMMENTS in the lessons as you can find great examples and explanations!👍
+ 10
When you need to do one particular thing: you want to always execute a block, and then 'maybe' repeat it.
int i=0;
do{
//do something
i++;
}while( i<10 );
The block of code is always executed at least once, regardless of the condition check at the bottom.
Then, until i is less than 10, we'll repeat the block.
+ 3
while loop check condition before execution of the loop& the do-while loop verifies the condition after the execution of the statements inside the loop.
+ 2
do {} while executes the code in its body at first and then checks the condition. while {}, on contrary, checks the condition and only then, depending on the result of its evaluation, moves on or not to its block. That means that do {} while will execute its code at least once, whereas simple while {} may not execute any code at all.
+ 1
There's a chapter covering the difference between the two.
https://www.sololearn.com/learn/C/2926/