.15 Looping with 'until'

How does this continue failing? The answer is printing out the numbers 50 to 1 but says Im still not printing out numbers 50 to 1.

i = 50
until i == 0 do
print i
i -= 1
end

This code should work. Make sure they want the print method and not the puts method.

The codes work. I have tried it.

I tried it as well and its not working for me

It needs to be until i = 1. It says the numbers 1-50 not 0-50. I made the same mistake and it took my like a half hour to figure it out. So anal this thing is…

3 Likes

No, if you replace i == 0 with i == 1, you’ll only print from 50 to 2.

No. I just did the code.

Then it’s not the same code as @jimijack’s, because if you apply i == 1 to his code, it won’t print all values.

Imgur

and

Imgur

1 Like

I had the same issue but I had to comment out the prior code that it put down to make it work. Seems to only want to process the “until” loop

1 Like

I think it is not perfect answer, but error has been gone when I did:
i = 1
until i == 51 do
print i
i += 1
end

1 Like

I have this:

i = 50
while i > 1 do
print i
i += 1
end

Yet, I get the following error:
The program took too long to finish. Check your code for infinite loops and try again.

Can anyone help?

Remember that the exercise wants you to count up from 1 to 50 inclusive. The following code worked for me:

i = 1
until i == 51 do
print i
i += 1
end

8 Likes

Folks! here is what I did and worked for me.
i = 1
until i > 50 do
print i
i += 1
end

So, the approach of making i == 51 works but somewhat does not do justice to the question. The asks 1 to 50 inclusive.

3 Likes

First you have to remove the previous codes

i = 1
while i < 51 do
print i
i += 1
end

then you have to make the new codes as below

i = 1
until i == 51 do
print i
i += 1
end

2 Likes

i=1
until i == 51 do
print i
i += 1
end

This is correct because you are including 50 but not exceeding 51 which satisfies the exercise.

2 Likes

This is what worked for me.
i = 1
while i <= 50 do
print i
i += 1
end

Correction I use while in my previous post the until iterator is what I wanted to post. see below;
i = 1
until i == 51 do
print i
i += 1
end

Thank you. I was killing myself trying to figure out what was wrong with my code (which was nothing) for ages before I deleted the previous code. Worked flawlessly. Great advice, 10/10, would heed again.

I did that as well to pass the exercise.