Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops For Loops

The sequence of for loop execute

Please correct me if I am wrong, is the sequence of for loop as follows?

for ( let i = 0; i <= 5; i ++ ) {
    console.log (i)
}

First: execute the statement 1 Second: check the condition of statement 2 Third: execute the code block Fourth: execute the statement 3 //which is the i ++ in this case?

In other words, the orders are as follow: statment 1> condition > code block > statement 3 ?

1 Answer

Steven Parker
Steven Parker
231,275 Points

That's basically it, except for the repeating. Adding that in:

  1. perform the init (first clause)
  2. check the condition (2nd clause), if false, quit the loop
  3. perform the code body
  4. perform the increment (3rd clause)
  5. go back to step 2