Export (0) Print
Expand All

10.1 Blocks

Visual Studio .NET 2003

Statements are organized into blocks, which are made up of logical lines. Each logical line begins with an optional label declaration, followed by zero or more statements delimited by colons.

Labels have their own declaration space and do not interfere with other identifiers. The following example is valid and uses the name variable x both as a parameter and as a label.

Function F(ByVal x As Integer) As Integer
    If x >= 0 Then
        GoTo x
    End If
    x = -x
x: 
    Return x
End Function 

The scope of a label is the body of the method containing it.

Note   Because both labels and statements are delimited with colons, it is possible for a label declaration to look like a statement; label declaration always takes precedence in any ambiguous situation.

Labels may be either identifiers or integer literals.

Execution of a block begins with the first statement in the block. Once a statement has been executed, the next statement in lexical order is executed, unless a statement transfers execution elsewhere or an exception occurs.

For the sake of readability, statement productions that involve multiple substatements are treated as a single production in this specification, even though the substatements may each be by themselves on a labeled line.

Block ::= [ LabeledLine+ ]
LabeledLine ::= [ LabelName : ] [ Statements ] LineTerminator
LabelName ::= Identifier | IntLiteral
Statements ::=
   [ Statement ] |
   Statements : [ Statement ]

See Also

10.1.1 Local Variables and Parameters | 10.2 Local Declaration Statements | 10.3 With Statement | 10.4 SyncLock Statement | 10.5 Event Statements | 10.6 Assignment Statements | 10.7 Invocation Statements | 10.8 Conditional Statements | 10.9 Loop Statements | 10.10 Exception-Handling Statements | 10.11 Branch Statements | 10.12 Array-Handling Statements

Show:
© 2014 Microsoft