ASP Getting Started Tutorial: ASP if Else tutorial

Source: Internet
Author: User

In any language, we all have the IF Else statement, the ASP in the if then else syntax is not like other programs, but the idea is the same.

If the declaration is used to make a decision, in your ASP program to execute some code, if some of the conditions are true. Since ASP is programmed in VBScript by default, when your ASP program declares it is actually the same programming language if declared.

If statement
The statement of ASP technology if slightly different is than executed if stated in most other languages. Without parentheses or curly braces, and without any parentheses. And the beginning of the code will be executed when the statement is made if its true characteristic is with the then and the end if the declaration is clearly marked out if. Here is a very basic statement, if it will ever be true.

<%
Dim MyNum
MyNum = 6
If MyNum = 6 Then
Response.Write ("Variable myNum = 6")
End If
%>
Results are: 6

You may notice that the "=" operator is used to determine the value of both sides mynum to 6 o'clock, and then use it to compare mynum to 6 if we declare. This dual-use equality operation is much messier, but it may help you to remember that in an ASP you cannot determine the value of a variable if the state, which means "=" can only be compared!

ASP if Else syntax

Sometimes, you may want to execute some code when both sides are true to the declaration and some different code when it is false. Like other programming languages, you can use other keywords in ASP. Here is an example that will always be false, and therefore other parts of the declaration if always executed.

<%
Dim MyNum
MyNum =
If MyNum = 6 Then
Response.Write ("Variable myNum = 6")
Else
Response.Write ("**variable myNum =" & MyNum)
End If
%>

Result is 23

ASP technology-e Lseif Conditional statement
With the normal statement if you can only check one condition, but sometimes you will have to check multiple conditions. In ASP, you can do this with ElseIf, which is the name of the declaration if dependent on another if declared.

Think about it in plain English: If the thing is true then do it elseif the second thing is really so do this, and so you may have used the ElseIf condition declaration in other programming languages, but if not just know, you can't have a ElseIf statement first, if there is a statement.

The following is an example if the second speaker (ElseIf) is always the case.

<%
Dim Myfastfood
Myfastfood = "Jbox"
If Myfastfood = "McD '" Then
Response.Write ("Happy Meal Por favor!")
ElseIf Myfastfood = "Jbox" Then
Response.Write ("Two tacos please!")
Else
Response.Write ("Foot-long turkey sub.")
End If
%>
Show Results:

Two Tacos please!
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.