Ruby初学者:无论是否包含结束语句,应用程序都会返回错误



我试图学习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而不是

相关内容

最新更新