Book Store  
  Contact Us  
  Links  
  Site Map  
ASP Scripts - if, then else descions

if ... then ... else

 

The If....Then...Else statement is used to execute code if certain condition is true.

<%

Dim aNumber
aNumber = 10
If aNumber = 10 Then
Response.Write("Number is 10")
End If

%>

In the above example, the text "Number is 10" will be displayed because aNumber = 10 is true

We can extend the above example to :

<%

Dim aNumber
aNumber = 20
If aNumber = 10 Then
Response.Write("Number is 10")
Else Response.Write("Number is NOT 10")
End If

%>

In the above example, the else statement is excuted so that the text "Number is NOT 10" is displayed.