+ 2

What is the difference between For and While...? Looks and works exactly same...!

5th Sep 2015, 7:13 AM
Anurag
Anurag - avatar
2 Answers
+ 6
They work similar, but have definite differences. The For-Loop allows specifics with iteration through the loop variable and is great to use when you know exactly how many times you want the code to iterate. The For-Loop checks statement1 for info, checks statement2 to see if statement1 is true, executes the code, and THEN applies statement3 to its parameters. While-Loops will simply execute the code over and over as long as the condition is true.
23rd Dec 2015, 1:03 AM
Aury Figueroa
Aury Figueroa - avatar
0
For - for as long as, While - while condition is, do 1 2 3 4. so the 2 loops are different.
15th Mar 2016, 4:50 PM
Lloyd Mwaluku
Lloyd Mwaluku - avatar