Name
If...Then...Else Statement
Syntax
IfconditionThen [statements] [ElseIfcondition-nThen [elseifstatements] ... [Else [elsestatements]] End If
Or, you can use the single line syntax:
IfconditionThen [statements] [Elseelsestatements]
-
condition(required; Boolean ) An expression returning either
TrueorFalseor an object type-
statements(optional) Program code to be executed if
conditionis true-
condition-n(optional) Same as condition
-
elseifstatements(optional) Program code to be executed if the corresponding
condition-nisTrue-
elsestatements(optional) Program code to be executed if the corresponding
conditionorcondition-nisFalse
Description
Executes a statement or block of statements based on the Boolean
(True or False) value of an
expression
Rules at a Glance
If
conditionisTrue, the statements following theIfare executed.If
conditionisFalseand noElseorElseIfstatement is present, execution continues with the correspondingEndIfstatement. IfconditionisFalseandElseIfstatements are present, the condition of the nextElseIfis tested. IfconditionisFalseand anElseis present, the statements following theElseare executed.In the block form, each
Ifstatement must have a correspondingEndIfstatement.ElseIfstatements do not have their ownEndIf. For example:If
conditionThenstatementsElseIfconditionThenstatementsEnd IfElseIfandElseare optional, and any number ofElseIfandElsestatements can appear in the block form. However, noElseIf ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access