Where Do ... An unconditional loop is documented?

Apparently, you can create Do ... Loop without a condition. The following code compiles with .NET 4.5 ( fiddle ), as well as Roslyn ( fiddle ):

 Public Sub Main() Do Console.WriteLine("Hello World") Exit Do Loop End Sub 

However, the grammar on the documentation page offers only the following two options:

 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 

Is this a bug in the compiler, a bug in the documentation, or just didn't look complicated enough?

+5
source share
3 answers

If in doubt, check out the language specification , not the link:

10.9.1 Until ... End While and Do ... Loop Statement

A While or Do loops loop statements based on a Boolean expression .... An expression can be placed after the Do keyword or after the Loop keyword, but not after .... It is also valid to not specify an expression at all;

(My emphasis)

A link to a language tries to be simpler, but may lose essential details. The language specification should match what the compiler implements.

+9
source

I think the key sentence in the documentation

You can use either Bye or Bye to indicate a condition, but not both.

So, if you want to specify a condition that you should use. Without a condition, you do not need to specify anything.

Leaving the condition, it is absolutely correct and will lead to an infinite loop.

+1
source

See the Details section below in the documentation:

condition Optional. Boolean expression . If the condition is Nothing , Visual Basic treats it as False .

-3
source

All Articles