Program Control

To direct the flow of program execution, the .NET languages support several control-flow statements. These act as you would expect. The following sections examine each, beginning with the popular if statement.

If Statements

There are two types of if statements, both of which require the use of a Boolean expression. These are the syntaxes for the most basic if statement:

VB

If boolean expression Then 
    ' Do some stuff here 
End If 

C#

if( boolean expression) 
{ 
    // Do some stuff here 
} 

JScript

if( boolean expression) 
{ 
    // Do some stuff here 
} 

Depending on the value of the Boolean expression, the body of the if statement may or may not be executed. If the expression evaluates to true, the body is executed. If the expression evaluates ...

Get Special Edition Using® Microsoft® ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.