Explain for loop in detail | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Explain for loop in detail

31st Oct 2016, 7:10 PM
riteshyadav
2 Answers
+ 3
for (initialization; condition; change) { body } First the "initialization" is done. Then the "condition" is checked. If the condition is true, the "body" of the loop is executed. If not, control passes to the statement (if any) directly after the body of the loop. After the body is executed, the "change" is done. This can be increment, decrement of the initialized variable(s) or something else. Now the condition is checked again & the procedure repeats as before. Observe that this is just like the while loop as shown below. initialization; while (condition) { body; change; }
19th Jan 2017, 12:13 PM
Dhaval Furia
Dhaval Furia - avatar
+ 1
loops are the conditional codes which keep on running when condition is true.. they stop when condition become false
31st Oct 2016, 7:25 PM
Shruti Singh
Shruti Singh - avatar