Do ... Loop without a condition 记录在哪里?
Where is Do ... Loop without a condition documented?
显然,可以创建一个没有条件的 Do ... Loop
-Loop。以下代码使用 .NET 4.5 (fiddle) as well as with Roslyn (fiddle) 编译:
Public Sub Main()
Do
Console.WriteLine("Hello World")
Exit Do
Loop
End Sub
但是documentation page上的语法只提供了以下两种选择:
Do { While | Until } condition
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop
-or-
Do
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop { While | Until } condition
这是编译器中的错误、文档中的错误还是我看得不够仔细?
请参阅文档下面的 部件 部分:
条件 可选。 布尔值 表达式。如果 condition 是 Nothing,Visual Basic 将其视为 False.
如有疑问,请参考 language specification,而不是参考:
10.9.1 While...End While and Do...Loop Statements
A While
or Do
loop statement loops based on a Boolean expression. ... An expression
may be placed after the Do
keyword or after the Loop
keyword, but not
after both. ... It
is also valid to specify no expression at all;
(我的重点)
语言参考试图更直接,但可能会丢失重要的细节。语言规范应与编译器实现的相匹配。
我认为文档中的关键句子是
You can use either While or Until to specify condition, but not both.
所以如果你想指定一个条件,你必须使用其中一个。如果没有条件,您不必指定任何内容。
离开条件是完全有效的,将导致无限循环。
显然,可以创建一个没有条件的 Do ... Loop
-Loop。以下代码使用 .NET 4.5 (fiddle) as well as with Roslyn (fiddle) 编译:
Public Sub Main()
Do
Console.WriteLine("Hello World")
Exit Do
Loop
End Sub
但是documentation page上的语法只提供了以下两种选择:
Do { While | Until } condition
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop
-or-
Do
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop { While | Until } condition
这是编译器中的错误、文档中的错误还是我看得不够仔细?
请参阅文档下面的 部件 部分:
条件 可选。 布尔值 表达式。如果 condition 是 Nothing,Visual Basic 将其视为 False.
如有疑问,请参考 language specification,而不是参考:
10.9.1 While...End While and Do...Loop Statements
A
While
orDo
loop statement loops based on a Boolean expression. ... An expression may be placed after theDo
keyword or after theLoop
keyword, but not after both. ... It is also valid to specify no expression at all;
(我的重点)
语言参考试图更直接,但可能会丢失重要的细节。语言规范应与编译器实现的相匹配。
我认为文档中的关键句子是
You can use either While or Until to specify condition, but not both.
所以如果你想指定一个条件,你必须使用其中一个。如果没有条件,您不必指定任何内容。
离开条件是完全有效的,将导致无限循环。