I don't know if this is possible as I haven't found anything on google
or in here. Is it possible to have an elsif to be looped?
$Str = gets.chomp
if $Str.to_i < 0
puts 'Sorry you cannot be that weak. Please enter a valid stat.'
elsif $Str.to_i > StartStats.to_i
puts 'You cannot give more stats than what you have available.
Please enter a valid stat.'
else puts 'Your Strength is '+($Str)
end
Is there a way to make this a loop so that if $Str.to_i < 0 it would
restart and ask for an input again? Even if the answer is the same it
would still restart?
I tried setting up a retry and redo but I couldn't get it to work.
$Str = gets.chomp
$Str.to_i < 0
until $Str.to_i > 0
puts 'Sorry you cannot be that weak. Please enter a valid stat.'
$Str = gets.chomp
end
$Str.to_i > StartStats.to_i
until $Str.to_i < StartStats.to_i
puts 'You cannot give more stats than what you have available. Please
enter a valid stat.'
$Str = gets.chomp
end
That site is an excellent resource.
Thanks again Steve.
That's a purely subjective point to make and, in my opinion, often untrue.
while !x.nil?
// body
end
vs.
until x.nil?
// body
end
is a simple example where I like the until version better. Once DeMorgan's
law kicks in for certain negations, until loops can become much cleaner. Example:
while !x.nil? || y < 0
// body
end
until x.nil? && y >= 0
// body
end
I personally think the until loop there is *much* simpler to read.