【发布时间】:2016-01-24 02:58:34
【问题描述】:
我试图重新提示用户的输入并重复使用它。这是代码示例:
print "Please put your string here!"
user_input = gets.chomp
user_input.downcase!
if user_input.include? "s"
user_input.gsub!(/s/,"th")
elsif user_input.include? ""
user_input = gets.chomp
puts "You didn't enter anything!Please type in something."
user_input = gets.chomp
else
print "no \"S\" in the string"
end
puts "transformed string: #{user_input}!"
我的elsif 会让用户知道他们的输入是不可接受的,但在重新使用他们的输入从头开始时无效。我该怎么做?我应该使用while 还是for 循环?
【问题讨论】:
-
我不知道你想做什么,但对于任何字符串
s,s.include? ""是true。 -
@sawa,你当然不知道,因为你没有问过他。