Welcome to the Treehouse Community
Looking to learn something new?
why "<=" instead of just "<"
I get that there may be situations where "<=" is warranted, but this does not seem like one. We're just printing a specified number of divs to a page in a for loop
Jason AndersTreehouse Moderator 145,623 Points
In my opinion, this would be an very good situation to use <= instead of just <. Because you are printing a specific number of DIVs, it is much easier to read that in the code using <=. The variable starts at one and the loop will run as long as the variable is "less than" or equal to 10. So, you would get 10 DIVs (1, 2, 3, 4, 5, 6, 7, 8, 9, 10). If you only used the < then you would only get 9 DIVs, because 10 is no longer "less than" 10. So, to get the same result, you would have to change you code to
i < 11
While this will produce the same result, I think this would be more confusing to read in code because you're not outputting 11 anythings, but rather everything less than 11. I think seeing a 10 when you want 10 things is just a bit more clear.
Both would be correct. This is just my opinion on it. :)