17. Loop the Loop with Loop


My link to exercise

This is what I get.
Oops, try again. It looks like you didn't print out the string 'Ruby!' 30 times.

counter = 0
loop do
  counter += 1
  print "Ruby"
  break if counter > 29

What is happening? I tried 29, 30 and 31. Please help!


Maybe you printed something slightly different from what you're meant to print.

As for figuring out which number you should stop at, consider what counter will be when it has printed once. Then just add 29 more times to that and now you know what value it should stop at.

Definitely better to write it as 30.times do though, leaving no doubt how many iterations are being made. (I realize the instructions might be telling you to do differently, my point is just that you should pick the way that is most clear to a human)


I got the same thing. You need to add the ! to the end of Ruby, so that it's "Ruby!"


Just add the "!", and change your break count to 30. Here's mines from the blackboard.

counter = 0
loop do
counter += 1
print "Ruby!"
break if counter == 30



Seriously?!?!?! You need to add "!" at the end of Ruby? WOW. just wow


Yeah this one is definitely bugged. Even copy pasting their own example and add in the number doesn't work. I too had to add ! at the end of the word Ruby. Would never have found out if not for this post.


Different method:

m = "Ruby!"
loop do
print m
break if 29.times { print m }


Correct syntax

i = 1
loop do

print "Ruby!"
i += 1
break if i > 30


Loop the Loop with Loop - Print Ruby error

It is so annoying when something doesn't work because of typo in the String. I understand when you did mistake in structure of program. But does it very important in text?


the exercise doesn't call for the .times do method


As I had some problems with a browser and with this task as well, I put my solution below:

m = 0
loop do
m += 1
print "Ruby!"
break if m==30