我很好奇是否有办法让程序回到if
语句堆栈?
理想情况下,程序会返回到第 2 行并提示用户输入变量,然后像第一次一样继续计算。把它想象成文本编辑器中的光标,我只想将它从这两个注释中的任何一个移回第 2 行。下面将两个感兴趣的地方注释掉:
while true
input = gets.chomp
if input != input.upcase
puts "HUH?! SPEAK UP, SONNY!"
elsif input == 'BYE'
puts "HUH?! SPEAK UP, SONNY!"
input = gets.chomp
if input == 'BYE'
puts "HUH?! SPEAK UP, SONNY!"
input = gets.chomp
if input == 'BYE'
puts "GOOD BYE!";
break
else
# return to top-level if statement
end
else
# return to top-level if statement
end
else
random_year = rand(1930..1950)
puts "NO, NOT SINCE #{random_year}!"
end
end