加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 04:19:31 所属栏目:百科 来源:网络整理
导读:例如,以下代码中是否存在do会影响程序的行为吗? while true do puts "Hi" breakendwhile true puts "Hi" breakend 解决方法 根据 The Ruby Programming Language书第5.2.1节: The do keyword in a while or until loop is like the then keyword in an if
例如,以下代码中是否存在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 an
if statement: it may be omitted altogether as long as a newline (or
semicolon) appears between the loop condition and the loop body.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读