Conditional statements are the set of commands used to perform different actions based on different conditions. In ASP, we use VBScript code to implement several types of conditional statements. All of the conditional statements produce a similar result but may be used in different ways depending on the conditions that are being evaluated.

If ThenIf Then…ElseIf Then…ElseIf…ElseSelect Case

HTML Sample

If Then

The simplest technique that can be used is to validate whether a condition is TRUE. You can execute this using one line of VBScript code. If you need to execute more than one line of VBScript code, then you write the additional lines of code under the If… Then Statement and terminate the block with an EndIf keyword.

If Then…Else

If you want to execute a statement if a condition is TRUE and execute another statement if the condition is FALSE, you can use the Else keyword:

If Then…ElseIf

The If…Then…ElseIf statements are used like the If…Then…Else expression, except that you can run through multiple comparisons. In this scenario, the process will first examine Condition-1. If Condition-1 is TRUE, the script will execute the first block of code and exit the process. If Condition-1 is FALSE, the process will continue to examine Condition-2. The same process continues. Whenever a condition is FALSE, the process will continue examining the conditions until it finds one that is TRUE or reaches the ELSE keyword. Once a TRUE condition has been found, its code is executed and the process exits. If none of the conditions are found as TRUE, the process will execute the code found in the ELSE block, if the ELSE keyword is included before the EndIf.

Select Case

The Select Case statements work in the same manner as If statements. You use the Select Case when you need to check for multiple values, not TRUE or FALSE. The Select Case statement allows a program to evaluate an expression and attempts to match the value of the expression to a specific Case. If a match is found, the program executes the associated statement within that Case. If no match is found, the program looks for the optional Case Else clause. If it exists, it executes the code within the Case Else block. If no Case Else statement is found, the process exits and the program continues to execute the next statement following the End Select.