语法错误,意外的输入结束,期待keyword_end ruby

时间:2014-09-18 04:16:25

标签: ruby

一个简单的CLI程序。我正在接受用户关于成分的输入,直到用户输入任何内容。用逗号加入所有成分并将其归还。

ingredient = []
int i = 0
ingredients = ""

puts "Enter ingredients :"

loop do
 puts "Ingredient #{i+1}"
 ingredient[i] = gets.chomp
 break if ingredient[i] = ""
 i++
end

ingredients = ingredient.join ","

puts ingredients

我不知道这有什么问题,但我不断收到错误"语法错误,意外的输入结束,期待关键字_end"。请帮忙。

1 个答案:

答案 0 :(得分:0)

ingredient = []
i = 0 # No int
ingredients = ""

puts "Enter ingredients :"

loop do
  puts "Ingredient #{i+1}"
  ingredient[i] = gets.chomp
  break if ingredient[i] == "" # == in comparison 
  i+=1 # NOT i++
end

ingredients = ingredient.join ","
puts ingredients