VBS Tutorial: VBscript statement-If... Then... Else statement

Source: Internet
Author: User

If... Then... Else statement

Execute a group of statements conditionally based on the expression value.

If condition Then statements [Else elsestatements ]

Alternatively, use the block Syntax:

If condition Then
[statements]
[ElseIf condition-n Then

[elseifstatements]] . . .
[Else

[elsestatements]]
End If

Parameters

Condition

One or more of the following two types of expressions:

Numeric or string expression. The operation result isTrueOrFalse. IfConditionIs Null, thenConditionConsideredFalse.

Expression in the format of TypeOf objectname Is objecttype. Objectname is a reference to any object, while objecttype is a valid object type. If objectname is an object type specified by objecttype, the expression is True; otherwise, it is False.

Statements

IfConditionIsTrueOne or more statements executed (separated by colons.

Condition-n

Same as condition.

Elseifstatements

IfCondition-nIsTrueOne or more statements that are executed.

Elsestatements

If noConditionOrCondition-nThe expression isTrueOne or more statements that are executed.

Description

For short and simple tests, you can use a single line (the first syntax ). However, the block form (the second syntax) provides more structured and adaptive than the single line form, making it easier to read, maintain, and debug.

Note:In a single-line syntax, You can execute multiple statementsIf... ThenBut all statements must be separated by colons on the same line, as shown in the following statement:

If A > 10 Then A = A + 1 : B = B + A : C = C + B

When the program runsIfBlock (second syntax), the testCondition. IfConditionYesTrue, Then executeThen. For exampleConditionYesFalse, Then eachElseIfSome conditional statements (if any) are calculated and tested in sequence. WhenTrueIs relatedThenThe subsequent statement is executed. If noneElseIfStatement isTrue(Or noElseIfClause ),Else. RunThenOrElseThe subsequent statement will be executed later.End If.

ElseAndElseIfClauses are optional. InIfBlock can be placed in any numberElseIfClause, but both must be inElseClause.IfBlock statements can be nested, that is, they are included in anotherIfBLOCK statement.

To determine whether a statement isIfBlock, can be checkedThenWhat is after the keyword. IfThenThe statement is in the form of a single row.IfStatement.

IfThe block statement must be the first statement of a row and must startEnd IfThe statement ends.

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.