What is the difference between do{}while () loop and while() loop in C programming? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between do{}while () loop and while() loop in C programming?

https://code.sololearn.com/cfhvTGysc4H7/?ref=app

13th Mar 2020, 7:04 AM
Binyaminu Zakariya
Binyaminu Zakariya - avatar
5 Answers
+ 10
Binyaminu Zakariya Please, Try to read the COMMENTS in the lessons as you can find great examples and explanations!👍
13th Mar 2020, 8:57 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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.
13th Mar 2020, 9:03 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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.
14th Mar 2020, 3:03 AM
Sakshi Sapkale
Sakshi Sapkale - avatar
+ 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.
13th Mar 2020, 7:29 AM
Axelocity
Axelocity - avatar
+ 1
There's a chapter covering the difference between the two. https://www.sololearn.com/learn/C/2926/
13th Mar 2020, 8:06 AM
Ipang