Revisiting Looping with 'For' 5.16


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


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.


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


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


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'


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


I was able to get my test to pass the way I had it written which was:
for j in 1..50
print j
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.


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


Thanks for getting back to me btw.


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