Loops with until why is my code right?


#1

this is my code for exercise 15 looping with until
y = 1
until y > 50 do
print y
y += 1
end
I don't really understand why this is right and all these are wrong
y = 1
until y < 50 do
print y
y += 1
end

y = 1
until y <= 50 do
print y
y += 1
end

y = 1
until y == 50 do
print y
y += 1
end


#2

i've kinda been confused with this whole section


#3

This,

y = 1                       
until y < 50 do
  print y
  y += 1
end

and this,

y = 1
until y <= 50 do
  print y
  y += 1
end

Never execute the loop since the until condition is already met. They would be a case for while.

This one is a risky way to write a loop condition. What if it never actually equals the number we've written. Better that it is an inequality, <, >, <=, >= that controls the loop.

y = 1
until y == 50 do
  print y
  y += 1
end

Your first example is correct.


#4

thank you I understand it a bit better now