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

iOS Objective-C Basics (Retired) Functional Programming in C Control Flow - For Loops

Why should I use I?

I've got a background with HTML/CSS and experience with Javascript and PHP, and I've learned those mostly through online tutorials. This always seems to be the phase when I'm learning a new coding tutorial that it goes a bit off the rails for me. The basics are covered and make total sense, then a bunch of stuff gets thrown out with insufficient information - in the "for" loop we have i=0 with no space, but our other integers always have a space between the equals sign (is there a reason for this, or is it cosmetic?); i is thrown in - why do we use i? what does it stand for? It could be just me and I'm a very visual person and this just isn't clicking with me just yet :) Just thought I'd bring it up. I'm loving Treehouse so far!!

3 Answers

Stone Preston
Stone Preston
42,016 Points

i is the counter variable (the space issue doesnt matter, the compiler ignores most white space. It could have been i = 0 just as well). i basically counts how many times the loop runs and then whenever the condition of the loop is unsatisfied it stops looping.

Thanks, Stone! That clears up a lot of things for me! :)

Stone Preston
Stone Preston
42,016 Points

its also worth noting that it doesnt have to be called i (although it almost always is in a classic for loop). it can be any variable, c, b, j, counter, loopCounter. i is just most common

Thanks, I was curious about that.