# FAQ: Loops & Iterators - Looping with 'Until'

This community-built FAQ covers the “Looping with ‘Until’” exercise from the lesson “Loops & Iterators”.

Paths and Courses
This exercise can be found in the following Codecademy content:

## FAQs on the exercise Looping with ‘Until’

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

## Join the Discussion. Help a fellow learner on their journey.

Agree with a comment or answer? Like () to up-vote the contribution!

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

When I write out the code for the ‘until’ loop and I run the following code

i = 0
until i >= 50 do
print i
i += 1
end

it prints 1 - 49. Any idea why?

1 Like

Not to be too obvious, but that’s exactly what you told the program to do. You start with `i = 0` then tell the computer to print `i` until `i >= 50`. You are adding `1` to `i` after each `print i` statement, so it prints the value of `i` until `i` gets to `50`. If you wanted to include the number `50`, just leave the `=` off of your until condition. Then it will print `i` until `i > 50`. Hope this helps!

3 Likes

yes it does! Thank you so much!

Hi.

I have been trying to use this solution you gave as a model for the solution to the Instructions for Lesson 5 Section 15 but I just can’t seem to figure it out. I think I’m confused about the range from 0-50 for the j = 3 section . Every time I try a new code using < 50 or 1…50 I end up in an endless loop.

i = 3
while i > 0 do
print i
i -= 1
end

j = 3
until j == 0 do
print j
j -= 1
end

## Now rewrite your `while` loop using `until`. You still want to `print` out the numbers 1 through 50, inclusive.

This is one of my many attempts which is wrong:

j = 3
until j ==0 < 50 do
print j
j -= 1
end

Thanks for any explanation you can give me.

Hi Midlidner,

I have a question for you but I incorrectly only sent it to bit4005433864. I would appreciate if you could please take a look at it as well.

Here it is:

Hi.

I have been trying to use this solution you gave as a model for the solution to the Instructions for Lesson 5 Section 15 but I just can’t seem to figure it out. I think I’m confused about the range from 0-50 for the j = 3 section . Every time I try a new code using < 50 or 1…50 I end up in an endless loop.

i = 3
while i > 0 do
print i
i -= 1
end

j = 3
until j == 0 do
print j
j -= 1
end

## Now rewrite your `while` loop using `until` . You still want to `print` out the numbers 1 through 50, inclusive.

This is one of my many attempts which is wrong:

j = 3
until j ==0 < 50 do
print j
j -= 1
end

Thanks for any explanation you can give me.

Unpinned

This topic is unpinned for you; it will display in regular order

Tracking

You will see a count of new replies because you posted a reply to this topic.

### Suggested Topics

Topic Replies Views Activity
FAQ: Getting Started - Generalizations

Ruby FAQ|0|155|Nov '18|

### [en_US.share.topic]

New Topic

Quote

Invalid dateInvalid date

Hi Midlidner,

I have a question for you but I incorrectly only sent it to bit4005433864. I would appreciate if you could please take a look at it.

Hi.

I have been trying to use this solution you gave as a model for the solution to the Instructions for Lesson 5 Section 15 but I just can’t seem to figure it out. I think I’m confused about the range from 0-50 for the j = 3 section . Every time I try a new code using < 50 or 1…50 I end up in an endless loop.

i = 3
while i > 0 do
print i
i -= 1
end

j = 3
until j == 0 do
print j
j -= 1
end

Now rewrite your `while` loop using `until`. You still want to `print` out the numbers 1 through 50, inclusive.

This is one of my many attempts which is wrong:

j = 3
until j ==0 < 50 do
print j
j -= 1
end

Thanks for any explanation you can give me.

Ok. Looks like you just need an `until` loop that will print the numbers 1 through 50. First we need a variable to increment through those numbers. Since we want to start with 1 we may as well initialize the variable that way: `j = 1`
Now we need an `until` loop with a condition that will stop after we print the number 50. We can use: `until j > 50 do` Now we’re in the clear! We print j and then add 1 to j inside the `until` loop’s code block, and we have what we wanted. Hopefully this helps. I’ve included the solution below if you get stuck.

``````j = 1
until j > 50 do
print j
j += 1
end
``````

Happy Coding!

2 Likes

Thank you very much!

1 Like

numbers.each { |element| puts element } with the use of the .each, what ist the point of a placeholder, wouldn’t it be easier to have numbers.each { puts}, removing the placeholder and just tipping out the required action?

This works without using the do function

i=1
until i>50
print i
i+=i
end

and

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

I get the same results

Hi everyone!

Is this code ok? It works, but should I use > 50 instead of == 51, or does it matter?

Thanks