Understanding for loops 🐷


I had a spent the better part of a day trying to solve this problem, and although I eventually did manage to make the for loop work I'm hoping somebody can help clarify why it works.

for (var i = 0; i < text.length; i++)

So if I'm understanding correctly we have 3 statements in the for loop:

  • The starting condition - var i =0;
  • The stopping condition - i < text.length;
  • The variable change statement - i++

Now, would I be correct in saying that the stopping condition is something that is essentially a boolean, and the for loop runs only while the statement is true?

Up until this point I had thought that the stopping condition was more like a check on when to stop, or in other words, the condition would only stop once the condition became true.


a for loop runs while the loop condition evaluates to true.


a for loop run until the the loop condition becomes false.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.