Call Exit Branching Statements

54 If On is specified, the compiler only allows implicit widening conversions; narrowing conversions must be explicit. If Off is specified, the compiler allows implicit narrowing conversions as well. This could result in runtime exceptions not foreseen by the developer. It is considered good programming practice to require strict type checking. The default is Off . See Sect ion 2.5.5 earlier in this chapter for the definitions of widening and narrowing conversions.

2.13.2 Branching Statements

Visual Basic .NET supports a number of branching statements that interrupt the sequential flow of program execution and instead allow it to jump from one portion of a program to another. These can be either conditional statements such as If or Select Case or unconditional such as Call and Exit .

2.13.2.1 Call

The Call statement invokes a subroutine or function. For example: Call SomeMethod When the invoked subroutine or function finishes, execution continues with the statement following the Call statement. If a function is invoked, the functions return value is discarded. The Call statement is redundant because subroutines and functions can be invoked simply by naming them: SomeMethod

2.13.2.2 Exit

The Exit statement causes execution to exit the block in which the Exit statement appears. It is generally used to prematurely break out of a loop or procedure when some unusual condition occurs. The Exit statement should be avoided when possible because it undermines the structure of the block in which it appears. For example, the exit conditions of a For loop should be immediately apparent simply by looking at the For statement. It should not be necessary to read through the entire loop to determine if there are additional circumstances under which the loop might exit. If a given For loop truly needs an Exit statement, investigate whether a different loop construct would be better suited to the task. If a given procedure truly needs an Exit statement, investigate whether the procedure is factored appropriately. The Exit statement has a different form for each type of block in which it can be used, as listed here: Exit Do Exits a Do loop. Execution continues with the first statement following the Loop statement. Exit For Exits a For loop. Execution continues with the first statement following the Next statement. Exit Function 55 Exits a function. Execution continues with the first statement following the statement that called the function. Exit Property Exits a property get or property set procedure. Execution continues with the first statement following the statement that invoked the property get or property set procedure. Exit Sub Exits a subroutine. Execution continues with the first statement following the statement that called the subroutine. Exit Try Exits the Try clause of a Try block. If the Try block has a Finally clause, execution continues with the first statement in the Finally clause. If the Try block does not have a Finally clause, execution continues with the first statement following the Try block.

2.13.2.3 Goto