17. Loop the Loop with Loop


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-ruby/lessons/loops-iterators/exercises/loop-the-loop-with-loop?action=lesson_resume

<In what way does your code behave incorrectly? Include ALL error messages.>
Why there’s only 1 “Ruby!” been printed out with the code below?

```

i = 1
loop do
print "Ruby!"
i += 1
break if i <= 31
end

<do not remove the three backticks above>

#2

i = 1 // You set i equal to one
loop do // start a loop
print "Ruby!"
i += 1 // After printing your string, increment i. i is now two
break if i <=31 //Stop the loop once i is less than or equal to 31

i = 2
2 <= 31
Therefore your loop will always run once and break.


#3

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