0

While loop vs for loop

What’s the difference between the two? From what I can see they seem fairly similar (sorry if the question makes you cringe, I’m new to coding)

27th Sep 2018, 7:05 PM
Noah Senesac
Noah Senesac - avatar
3 Answers
+ 7
For loop is used when you know the exact number of iterations. Let's say there are hundred students and you have to mark their attendance. Now you know the exact iterations i.e 100 While loop is used when you do not know the exact iterations, like how many times the loop will run. Let's say your program keeps taking non-zero values from the user, now whenever the user input zero the loop will be terminated. In this situation, you don't know how many times loop iterated
27th Sep 2018, 7:38 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 3
Noah Senesac haha no prob.😀 The while loop run until the condition is false example: if the company has money pay the workers. when the company does not have money it ends. The For loop is different it typicaly needs three things. a iteration -> at start point/counter an end case -> when to start and the potion the brings you closer to the end condition. such as the plus 1 when you count.
27th Sep 2018, 7:15 PM
Manual
Manual - avatar
+ 1
Noah Senesac They are basicaly the same for each programming language. But tend to have different syntax or grammar.
27th Sep 2018, 7:17 PM
Manual
Manual - avatar