+ 2
Hello please what is the main difference between a while looo and a for loop.
Loops
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.
+ 8
Please use đbar next time to avoid duplicate
https://www.sololearn.com/Discuss/135277/?ref=app
https://www.sololearn.com/Discuss/1449574/?ref=app
https://www.sololearn.com/Discuss/42317/?ref=app
https://www.sololearn.com/Discuss/1317347/?ref=app
https://www.sololearn.com/Discuss/1317523/?ref=app
https://www.sololearn.com/Discuss/1630088/?ref=app
+ 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.
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
0
While loop is executed , until a given condition is satisfied ,then it will terminate .whereas for loop
0
is used for initialization, condition for specified no of times and increment