14. Looping with 'While'


#1



My link to 14. Looping with 'While'


This is what I get.
(ruby):4: syntax error, unexpected $end, expecting keyword_end


i = for num in 1..50
while i < 50 do
  print i
  i += 1
end

Can you help me? Thanks!


#2

Hey there, got pretty stuck on this too. firstly define I as just 1, so you get a starting point.
In your while section do I < 51, so you go upto but not over, 50.
The rest looks good to me. Here is the overall loop:

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


#3

Can you perhaps explain why start with 1 and not 0 ?


#4

@aleafonthewind

You start with 1 and not 0 because you have to print from 1 to 50, inclusive, so if you start with 1, it will be easier.


#5

High there. Can someone explain to me why you set i to 1 and increment it up to 50? also, why does using an inclusive range (1 .. 50) not work?


#6

i = 1
while i < 51 do
    print "#{i} \n"
    i += 1
end

why did this not work? Says didn't print 1 to 50 inclusive
also tried printing reverse to see if it worked, but still no


#7

Hi there try this

i = 1
while i < 51 do
print "#{i}"
i += 1
end


#8

What was different from my code?


#9

This should work

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

#10

this work

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