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 follow 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 the example above, is used to execute a block of code which extends over more than one line.
If there is only a single statement to execute it can all be brought together as a single statement, on one line and omitting the End IF.
<%
If time < 12:00 then response.write("Good morning, welcome to ...")
%>
The If statement may be further extended so that if the condition is met we do one action, otherwise we will do another.
The extended example is shown below, complete with the inclusion of an else statement.
<% If time < 12:00 then %> Good morning, welcome to ... <% Else 'time < 12:00 %> Good afternoon, welcome to ... <% End If 'time < 12:00 %>


