asp.net.ph

Skip Navigation LinksHome > Getting Started > ASP.NET Programming Languages Primer > If Statements

ASP.NET Programming Languages Primer


The if statement ( If...Then in VB ) executes embedded statements if a condition evaluates to true.

if ( condition ) {
   ... statements ...
} else {
   ... statements ...
}
  C# VB JScript

Key Points

  • The condition can be any valid expression that evaluates to true or false.
  • The if statement can optionally include an else clause.
  • Any valid statement can follow the if or else statement, including further if statements.

NOTE: In C# and JScript, if more than one statement follows a control statement, such as an if or else statement, the statements must be enclosed within braces { }.

An if statement is executed as follows:

  • The condition is evaluated.
  • If the condition is true, the statements within the if block are executed.
  • If the condition is false, and an else part is present, the statements within the else block are executed.
  • Thereafter, control is passed to the statement after the if...else block.

The following example demonstrates use of an if...else statement to display a greeting depending on the time of day.

 Show me 

More ...
Back to top


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note