do & for | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

do & for

when we use do and when we use for ??

4th Sep 2020, 6:21 PM
Mohamed Chouai
Mohamed Chouai - avatar
4 Answers
+ 5
Please use propper tags for programming language. Thanks!
4th Sep 2020, 6:31 PM
Lothar
Lothar - avatar
+ 2
In c and c++ , the concept and syntax of loops are same, in c/c++ the 'for' loop is for(init; expression; increment); That's a syntax of for loop, in this case: init - init is the base condition, or staring point of the loop, expression - that's repeating time/turns of loop, and the increment for incrementation in for loop. Do while loop- that's have similarities to while loop, only one difference in it is that, that should be execute at least once, without check any condition, Syntax (do while) : do { // Statements; } while (condition);
4th Sep 2020, 7:31 PM
Rupali Haldiya
Rupali Haldiya - avatar
+ 1
For is an entry controlled loop meaning the condition will be checked first before executing for looop. Do is an exit controlled loop meaning it will execute once before checking the condition. The usage depends on your need.
4th Sep 2020, 7:25 PM
shubham kumar
shubham kumar - avatar
0
Purpose of the loops are the same, you just write loops on different way. There are while, do-while and for loops.
6th Sep 2020, 4:53 AM
TeaserCode