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 trialShung Chen
6,526 PointsThe 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
231,236 PointsThat's basically it, except for the repeating. Adding that in:
- perform the init (first clause)
- check the condition (2nd clause), if false, quit the loop
- perform the code body
- perform the increment (3rd clause)
- go back to step 2