ASP If Statements
Using if statement, ASP has the ability to make distinctions between
different possibilities. For example, you might have a script that checks if
a variable consists certain type of values. Here is syntax for
asp if statement.
<%
if condition is true then do something
else
do something else end if
%>
Check the following if statement that checks if a variable
has a value equal to 1.
<%
dim n n =1
if n= 1 then
response.write("N has the value equal to 1")
else
response.write("N is not equal to one")
end if
%>
|
Nested If Statement
You would be able to check variety of conditions based on deversified values.
The following example is nested if statement to check
two conditions:
<%
dim fruit1, fruit2, in_store
fruit1="Apple"
fruit2="Orange"
in_store=1
if in_store=1 then %>
<%=fruit1%> is in store
<%
else if in_store=2 then %>
<%=fruit2%> is in store
<% else response.write("No value specified")
end if %>
| This if statement will check if the variable in_store
is equal either 1 or 2 and displays fruit1 or fruit2 according to the
true condition. <%=fruit1%> will display the value
of the specified variable. It's similar to response.write(fruit1).
|
|