15. Looping with 'Until' error


#1

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

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

this code is creating the desired output but its still saying u didn't print 1 through 50, inclusive. Help me out folks.


#2

Do you have both of these loops in your code? Because I think they're only asking for one right?


#3

So wait, all I gotta do is put 51? How does that make sense? I had that originally but why would you have ("==" equal to) 51? I feel like it's technically saying is equal to 51. I don't know. I can't wrap my brain around this.


#4

51 or 50 can work just as well, it all depends on the type of loop you use and the condition you use with them.


#5

try this

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

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


#6

Try this code. This one worked for me.

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


#7

I have the same question opdlnando. Bump.
Why does this code only go to 49?

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

#8

hi @arrozconcurry!

I believe it is due to the fact that the until loop will execute that line of code "until" that condition is true. So, if i = 50, that means the condition is now true therefore it would not run that loop. Hope that helps! :slight_smile:v


#9

this will work

i = 1
until i > 50 do #it should be greater not equal or less than 50
print i
i += 1

end


#10

Thank you. It works.