"If" statement is a control structure to determine the flow of the ASP page, using conditions given by user. The basic sytax is like this:
This code translates as: "If -condition- is true then execute -this-, if not then execute -something else-". "If" statement can be extended using "ElseIf" statement. The syntax is like this:
This code means: "If -condition- is true then execute -this-, if not true but -another condition- is true then execute -that-, if both conditions are not met then execute -something else-". You can use several "ElseIf" statements to check several specific conditions:
"ElseIf" and "Else" statements are not required, you can use "If" alone:
Examples:
This code will give the following result:
VBScript has the following comparison operators to use in condition checking: = : Equal to < : Less than <= : Less than or equal to > : Greater than >= : Greater than or equal to <> : Not equal to You can use "AND" and "OR" operators to check more then one condition in every "If"/"ElseIf" statement. For example:
The code executed after condition checking is not limited to one line, there could be limitless counts of lines executed. For example:
|