Hi - sorry to bother with such a basic question, but is there a better
way
to write the following: (before I move on I want to make sure I am
following
best practice)
def require_number(prompt, max)
print prompt
reply = gets.to_i
if reply >= max then reply = require_number "Please enter a number
less than #{max}: ", max end
reply
end
require_number 'Please enter a number: ', 100
Thank you for taking the time - could I trouble you further? If I want
the “reply” to iterate through until it reaches 100 could just add the
“while” to your code as below?
def require_number(prompt, max)
print prompt
reply = gets.to_i
if reply >= max then reply = require_number "Please enter a number
less than #{max}: ", max end
while reply < max
reply = reply + 1
puts reply
end
end
require_number 'Please enter a number: ', 100
Thank you for taking the time - could I trouble you further? If I want
the “reply” to iterate through until it reaches 100 could just add the
“while” to your code as below?
while reply < max
reply = reply + 1
puts reply
end