Revisiting Looping with 'For' 5.16


#1

Someone answered this but it didn't work for me.
Instruction asks to print 1 to 50 inclusive using the for loop

this is what I did:

for k in 1..50
    print k
end

#2

And what is your question? Aside from the fact, that it would make sense to separate the printed numbers by something (space, comma, newline) for easier reading, your solution is correct. Of course it is a bit odd to use a for loop over a range to achieve the goal, but it works.


#3

I'm still getting an error message:
"Oops, try again. It looks like you didn't print out the numbers 1 to 50, inclusive."


#4

I'm experiencing the same problem. Did you ever get the test to pass?


#5

Hi, yes I did. so the way I understand it is you first want to identify what you'll be working on after you use 'for' in this case it is '1..50' and then also add 'do'


#6

In case that was even more confusing. for k 1..50 in 1..50 do
the rest is the same


#7

I was able to get my test to pass the way I had it written which was:
for j in 1..50
print j
end
I just had to delete the until and while loop that were still on my console from the previous two steps even though during the last step (until) I didn't need to delete the while loop from the preceding step to get that test to pass.


#8

I don't think you need to include "do" in a for loop.


#9

Thanks for getting back to me btw.


#10

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