Many thanks for all that reply to my question.

So, i tried this (using the Martin's example):

--8<--

result = while true do
          print 'Try? '
          input = gets.chomp
          exit if input == 'quit'
          break input.to_i if input.to_i.to_s == input
          puts "Please, a number."
          end

puts "You entered #{result}"

-->8--

It works, but checking with rubocop :

--8<--

debug.rb:1:1: C: Carriage return character detected.
result = while true do ...
^^^^^^^^^^^^^^^^^^^^^^
debug.rb:1:10: C: Use Kernel#loop for infinite loops.
result = while true do
          ^^^^^
debug.rb:1:16: W: Literal true appeared in a condition.
result = while true do
                ^^^^
debug.rb:1:21: C: Do not use do with multi-line while.
result = while true do
                     ^^
debug.rb:2:10: C: Use 2 (not 0) spaces for indentation.
          print 'Try? '

debug.rb:6:15: C: Prefer single-quoted strings when you don't need 
string interpolation or special symbols.
          puts "Please, a number."
               ^^^^^^^^^^^^^^^^^^^
debug.rb:10:1: C: 1 trailing blank lines detected.

1 file inspected, 7 offenses detected

-->8--

Can you help me to troubleshoot this ?
I use also codebeat to review code, it accepts less than 10 lines per 
method.
How can i refactor that ?

Thank you very much for all your replies.

Regards,

/Nathan


Le 2016-11-30 12:14, Martin DeMello a crit :

> The 'break value' statement is another option:
> 
> result = while true do
> print "Enter a number: "
> input = gets.chomp
> if input == "quit"
> exit
> elsif input.to_i.to_s == input
> break input.to_i
> end
> end
> 
> puts "You entered #{result}"
> 
> Calling "break" with a value makes that value the return value of the 
> loop, which is what you want here.
> 
> martin
> 
> Unsubscribe: 
> <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>