O'Reilly logo

Learning Visual Basic .NET by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Branching

A method is, essentially, a mini-program within your larger program. It is a set of statements that execute one after the other, as in the following:

Sub MyMethod( )
End Sub

Methods are executed from top to bottom. The compiler reads each line of code in turn and executes one line after another. This continues in sequence until the method branches. Branching means that the current method is interrupted temporarily and a new method or routine is executed; when that new method or routine finishes, the original method picks up where it left off. A method can branch in either of two ways: unconditionally or conditionally.

As the name implies, unconditional branching happens every time the program is run. An unconditional branch happens, for example, whenever the compiler encounters a new method call. The compiler stops execution in the current method and branches to the newly called method. When the newly called method returns (i.e., completes its execution), execution picks up in the original method on the line just below the line where the new method was called.

Conditional branching is more complicated. Methods can branch based on the evaluation of certain conditions that occur at runtime. For instance, you might create a branch that will calculate an employee’s federal withholding tax only when her earnings are greater than the minimum taxable by law. VB.NET provides a number of statements that support conditional branching, such as If, ElseIf, and Select ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required