gpt4 book ai didi

ruby - Ruby 什么时候需要 do 关键字?

转载 作者:数据小太阳 更新时间:2023-10-29 06:57:26 27 4
gpt4 key购买 nike

例如,以下代码中是否存在 do 是否会影响程序的行为?

while true do
puts "Hi"
break
end

while true
puts "Hi"
break
end

最佳答案

根据 The Ruby Programming Language本书第 5.2.1 节:

The do keyword in a while or until loop is like the then keyword in anif statement: it may be omitted altogether as long as a newline (orsemicolon) appears between the loop condition and the loop body.

所以,不,它不会改变行为,它只是可选语法。

关于ruby - Ruby 什么时候需要 do 关键字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27908987/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com