Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops The Refactor Challenge

initialExpression

Hi Guys, I have been able to complete the challenge can someone explain in more details about the initialExpression in for loops and the purpose behind it.

Thanks

Nick Welch
Nick Welch
5,725 Points

I just want to confirm what you mean by initialExpression. for example consider this loop.

for (var i = 1; i <= 10; i += 1) { //do something }

for defines the for loop. var i = 1 creates a variable named i and initializes it's value to 1. We use this as a counter as the loop executes. i <= 10 is the condition for the loop to keep running. In this case it will only keep running if our counter, i, is less than or equal to 10. i += 1 increments the counter each time it runs. This way the loop will eventually stop running.

Is this what you were needing more help with? If so I hope my response helped to clarify things. If you need additional help let me know.