15. Looping with 'Until'


#1

Hey everyone! Can someone please explain to me why does the == comparator have to equal to 51 in order to include 50 when printing? Is that how it always works? How can I make it so that it includes 50?

https://www.codecademy.com/en/courses/ruby-beginner-en-XYcN1/3/2?curriculum_id=5059f8619189a5000201fbcb

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


#2

This excludes the value 51 from the loop. It is the exit condition. Consider,

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

Using the inequality lets us use the literal that makes the most sense.


#3

That makes so much more sense! Thank you!!!


#4

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