Use break keyword in the method body
<p>I have two loops here:</p>

<pre><code>loop do
  prompt(messages('APR_amt', LANGUAGE))
  APR_amt = Kernel.gets.chomp

  if valid_number?(APR_amt)
    break
  else
    prompt(messages('not_valid_num', LANGUAGE))
  end
end

loan_duration = ''
loop do
  prompt(messages('loan_duration', LANGUAGE))
  loan_duration = Kernel.gets().chomp()

  if valid_number?(loan_duration)
    break
  else
    prompt(messages('not_valid_num', LANGUAGE))
  end
end
</code></pre>

<p>This part keeps on repeating for every loop:</p>

<pre><code>if valid_number?(loan_duration)
  break
else
  prompt(messages('not_valid_num', LANGUAGE))
end
</code></pre>

<p>Just different variable passing by on it. 
Now what I did is that I created a method for it to shortened my codes:</p>

<pre><code>def check_number(varname)
  if valid_number?(varname)
    break
  else
    prompt(messages('not_valid_num', LANGUAGE))
  end
end
</code></pre>

<p>But this one did not work. Instead I got an error that pertains to break.
How can I create a method that will work on all of my variables? </p>