STUCK loops and iterators- Ruby-"looks like you didnt print numbers 1 - 50 inclusive"


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

#2

Put the number of the lesson you are working on.


#3

I figured it out sorry! Thank you :smile:


#4

I am having a similar issue with "until"

Loops and Iterators.15

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

says 1 to 50 is not inclusive ... I've looks at the examples and previous practice problems. Am I missing somethings? Thanks for help.


#5
until num == 50

What happens when num contains 50?


#6

Inclusive means your code should print 50. The code shown will not print 50 so it is "not inclusive". A good way to understand why this is the case is to try to step through in your head what will happen when i = 50 and the interpreter executes the line until num == 50.


#7

So can you show me how to format this correctly, because apparently I have no idea how to move forward from here.


#8

Your formatting is fine, your range is wrong. If you indent the 2 lines between do, end it will be easier to read. However, that will not change how your code works.


#10