17. Loop the Loop with Loop


#1



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
end

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


#2

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)


#3

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


#4

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

end


#5

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


#6

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.


#7

Different method:

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


#8

Correct syntax

i = 1
loop do

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

end


Loop the Loop with Loop - Print Ruby error
#9

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?


#10

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


#11

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
end