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)
3 RĂ©ponses
+ 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
+ 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.
+ 1
Noah Senesac
They are basicaly the same for each programming language.
But tend to have different syntax or grammar.