Ruby Ruby Loops Ruby Loops The Ruby Loop

Jonas Troyer
Jonas Troyer
10,912 Points

Why is this saying yo instead of hi?

Why is my code giving me back yo instead of hi, I don't see where it is inputting these statements into my code?

loop.rb
def repeat(string, times)
  fail "times must be 1 or more" if times < 1
  counter = 0
  loop do
    puts string
    counter += 1
    if counter > 4
      break
    end

  end
end

1 Answer

Brandon McClelland
Brandon McClelland
4,645 Points

You should be assigning the string to repeat when you call the repeat method.

repeat('hi', 3)

vs.

repeat('yo', 5)