The if then ... else ... end if statement is one of the core
statements used in ASP. Using this statement we can test if a
condition is met, then dependant upon the result make one of two
actions. As an example we will show a greeting on the page if its the
morning.
<%
If time < 12:00 then
%>
Good morning, welcome to ...
<%
End If
%>
The format used in our example above, is used to execute a block of
code which extends over more than one line. If we only have a
single statement to execute we can make it more efficient, by putting
the whole statement on one line and omitting the End IF.
<%
If time < 12:00 then response.write("Good morning, welcome to ...")
%>
To help you in debugging your program, it is worth adding a comment after the End If so you know which If block it relates to.
The If statement may be further extended so that if the condition is
met we do one action, otherwise we will do another. We do this
using the Else statement.
<%
If time < 12:00 then
%>
Good morning, welcome to ...
<%
Else 'time < 12:00
%>
Good afternoon, welcome to ...
<%
End If 'time < 12:00
%>
| This article viewed: 2028 times | Back |
Copyright © 2004-2007 Janet Systems Ltd.