|
If...Then...Else statement |
Format:
If condition Then
[ statements ]
[ ElseIf <elseifcondition> Then
[ elseifstatements ] ]
[ Else
[ elsestatements ] ]
End If
Syntax:
Remarks:
1. When a If...Then...Else is encountered, condition is tested.
If condition is True, the statements following Then are executed.
If condition is False, each ElseIf statement is evaluated in order.
When a True elseifcondition is found, the statements immediately
following the associated Then are executed. If no elseifcondition
evaluates to True, or if there are no ElseIf statements, the statements
following Else are executed. After executing the statements following Then,
ElseIf, or Else, execution continues with the statement following End If.
2. The ElseIf and Else clauses are both optional. You can have as many
ElseIf clauses as you want in a If...Then...Else statement, but none can
appear after an Else clause.
3. If...Then...Else statements can be nested within one another as many
times as needed.
See also: Select Case statement might be more useful when evaluating a single
expression that has several possible values.
See also:
Example:
Input "Imput your number: ", Number
if Number < 10 then
Digits = 1
elseif Number < 100 then
Digits = 2
elseif Number < 1000 then
Digits = 3
else
Digits = 4
endif
Str = "Your number has "
if Digits = 1 then
str = str + Digits + " digit!"
elseif Digits < 4 then
str = str + Digits + " digits!"
else
str = str + Digits + " or more digits!"
endif
print Str
input 'wait for enter to continue
Copyright (c) 2000-2006 by Smartphoneware. All rights reserved.