且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-12 21:30:46

根据 The Ruby Programming Language 书第 5.2.1 节:

According to The Ruby Programming Language book Section 5.2.1:

whileuntil 循环中的 do 关键字类似于if 语句:只要换行(或分号)出现在循环条件和循环体之间.

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.

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

So, no, it won't change the behavior, it's just optional syntax.