+ 2

Hello please what is the main difference between a while looo and a for loop.

Loops

1st Mar 2019, 10:46 AM
Wise Letson
Wise Letson - avatar
6 Answers
+ 10
You know exactly how many times your loop will run with a for loop. But with a while loop it is not quite possible to predict.
1st Mar 2019, 4:40 PM
Mitali
Mitali - avatar
+ 1
In while you check one condition everytime. In for loop you increase a variable each loop(it's optional. You can do anything) and check the condition. For acts exactly in same way as while and they are interchangeable but for is enhanced and optimized for some specific loops.
1st Mar 2019, 10:52 AM
Parsa Gholipout
Parsa Gholipout - avatar
0
technically, they do the same thing, but in different situations it's more convenient to use 'while' or 'for'. for example, 'while' can be used when the number of iterations is unknown and the code must loop until the condition is true
1st Mar 2019, 10:53 AM
Before
Before - avatar
0
While loop is executed , until a given condition is satisfied ,then it will terminate .whereas for loop
1st Mar 2019, 6:42 PM
Anil Kumar
0
is used for initialization, condition for specified no of times and increment
1st Mar 2019, 6:43 PM
Anil Kumar