我试图让遍历if语句,如果用户输入无效它都跟只输入数字或断裂,如果真的红宝石使用,如果内环路与用户输入
我想这是我的代码
class String
def numeric?
Float(self) != nil rescue false
end
end
cond = false
puts "Enter number "
line = gets.chomp.strip
while cond == false
if (line.numeric? )
puts "Ok nice "
cond = true
else
puts "Please enter number only "
end
end
但它一直循环,如果条件是假的只是印刷“请输入号码只有”
我会为任何建议非常高兴
谢谢
你不要求另一条线路。 –