我正在尝试通过使用 while 循环从用户那里获取有效输入。因此,如果输入无效,我希望每次用户未提供有效输入时都会出现错误消息并重复出现
这是我的代码 -
def suburb
#user prompt to get information for URL
puts ' Hey there welcome to house_search! Please which suburb you would like to search...'
puts '1. sub1 2. sub2'
suburb_input = input
while suburb_input != "1" or "2"
p "please try again"
suburb_input
end
end
有谁知道做到这一点的最佳方法?