FAQ: Loops & Iterators - The 'For' Loop

This community-built FAQ covers the “The ‘For’ Loop” exercise from the lesson “Loops & Iterators”.

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

Learn Ruby

FAQs on the exercise The ‘For’ Loop

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 (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.

Ask or answer a question about this exercise by clicking reply (reply) below!

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

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

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!

So I ran this program and to me it should print the numbers 1 thru 10, but it prints 1 thru 9 - why?
The code is:

for num in 1…10
puts num
end

To me it looks like it counts, prints then ends through the number 10 not until the number 10.

Well, I should have clicked next, the next lesson direction tell me that the … say stop before last value. Seems like an odd rule, and they say English is the hardest language to learn. lol.

4 Likes

Ruby is supposed to be easy to read and understand. I don’t know how “for num in 1…10” is easier than basic For i= 1 to 10. Just my opinion here.

Hey @fenderman9

I don’t know… for num in 1...10 seems to have better readability. For example, if someone looked over the ruby code, they’d be able to immediately see what that was going to do, or at least guess at it, whereas:

is probably a little bit more confusing.

hi ! I have a question about “for num in 1 … 10”
why does the result include 1 but not 10 ?
thanks

woops nevermind, the exercice just explains why in the next step