ASP if Then else syntax and if Then else instance tutorial

Source: Internet
Author: User

If statement a method that makes a variable or some other type of data to make a decision. For example, you may have a

Script to check if the Boolean value is True or FALSE, or the variable contains a number or string value.

Use the IF statement to execute the statement if the logical condition is true. Use an optional other clause to execute the statement if

Condition is false. The syntax for a seemingly if statement is as follows:
If condition Then
Statements_1
Else
Statements_2
End If
The condition can be any expression with a value of true or false. If the condition is true, Statements_1 is

Line, otherwise, the statements_2 is executed. Statement_1 and statement_2 can be any statement, including

A further nested if statement.

You can also use compound declarations to elseif multiple conditions in a sequential order. You should use this building if you want to select

Multiple sets of lines to execute.
If Condition_1 Then
Statement_1
[ElseIf Condition_2 Then
Statement_2]
...
[ElseIf Condition_n_1 Then
Statement_n_1]
[Else
Statement_n]
End If
Let's take the example. The first example determines whether a student has passed a pass score of 57 exams:

Select Actionselect alltry it<%@ language= "VBScript"%>
<%
Dim result
result = 70

If result >= Then
Response.Write ("Pass <br/>")
Else
Response.Write ("Fail <br/>")
End If
%> Next example uses an if statement in ElseIf variants. This lets us test if the first other condition is not

Right. The plan will test each sequence state until:

One of its discoveries is true. In this case, the code that executes this condition.
It arrives at an else statement. In this case, the code that executes the ELSE statement.
It arrives eventually if ... elseif. else structure. In this case, moved to the next speaker, after having

The structure of the condition.
Select Actionselect alltry it<%@ language= "VBScript"%>
<%
Dim result
result = 70

If result >=-then
Response.Write ("Passed:grade A <br/>")
ElseIf result >= Then
Response.Write ("Passed:grade B <br/>")
ElseIf result >= Then
Response.Write ("Passed:grade C <br/>")
Else
Response.Write ("Failed <br/>")
End If
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.