16. Looping with For


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/courses/learn-ruby/lessons/loops-iterators/exercises/looping-with-for?action=lesson_resume
<In what way does your code behave incorrectly? Include ALL error messages.>
I was wondering my code is:

for i in 1…50
print i
end

which prints out 1 to 50 correctly but wont let me pass the lesson. I decided for them to show me the code and theirs was

for i in 1…50
print i
i+= 1
end

what is the point of incrementing i when it has the same output.



Replace this line with your code. 



#2

Hi there! @dnangel1 :smiley:
Well, the for loop statement is just stating that you’re going to loop through a range and you need to specify by HOW MUCH. So i+=1 just means increment the var i by 1 every time I loop through this block of code once and so on.

Hope this helps


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.