我试图学习Ruby教程,但遇到了这样的情况:我的代码为while块返回错误。
如果我在while块的末尾包含"end",就像这样:
while attempts < 3
puts "Please input your username."
usernameTest = gets.chomp
puts "Please input your password."
passwordTest = gets.chomp
attempts++
end
它以syntax error, unexpected
结尾"返回。
但是,如果我删除最后一条end
语句,它将返回syntax error, unexpected end-of-input
。因此,它似乎无法决定是否想要end
声明。
attempts++
在Ruby中无效,您需要使用attempts += 1
而不是