elseif
FORMULA

The elseif statement allows multiple if decisions to be chained together.


Parameters

This statement has one parameter:

formula – is a formula that decides whether or not to execute the following statements. The result of this formula must be a Boolean (true/false) value.


Description

The elseif statement allows a series of decisions to be chained together so that one, and only one, of the decisions will be taken. The elseif statement must be combined with the if and endif statement, and can also be used with the else statement.

For example, suppose you want to ship a package, and you have seven different options for shipping the package. Only one of these can be used for any one package, so the elseif statement is perfect.

if shipMethod = "US Post Office"
    Rate = 3.50
elseif shipMethod = "UPS Ground"
    Rate = 5.00
elseif shipMethod = "UPS Blue"
    Rate = 8.00
elseif shipMethod = "UPS Red"
    Rate = 15.00
elseif shipMethod = "Fedex Ground"
    Rate = 6.00
elseif shipMethod = "Fedex 2nd Day"
    Rate = 9.00
elseif shipMethod = "Fedex Overnight"
    Rate = 20.00
else
    Rate = 25.00
endif
message "Shipping rate is "+Rate

Panorama starts at the top and checks the shipping method for each if or elseif statement. Suppose that the shipping method is UPS Blue. Panorama will skip the Rate = 3.50 and Rate = 5.00 statements and set the rate to 8.00. It will then skip all the way to message statement at the end and display the rate.

The example above includes an else statement near the bottom. If an else statement is included, the statements below it will be executed only if none of the elseif formulas above are true. There must not be any elseif statements between the else and endif statements (unless they are nested between another if/endif pair, see below).

Note: Be careful to note that elseif is one word, not two. If you put a space between else and if the meaning is entirely different, and you’ll probably see errors you didn’t expect.

You can nest if-elseif-else-endif constructs, allowing for multiple levels of decisions like this:

if shipMethod = "US Post Office"
    Rate = 3.50
elseif shipMethod = "UPS Ground"
    Rate = 5.00
elseif shipMethod = "UPS Blue"
    Rate = 8.00
elseif shipMethod = "UPS Red"
    if Weight > 10
        Rate = 50.00
    elseif Weight > 5
        Rate = 30.00
    elseif Weight > 2
        Rate = 20.00
    else
        Rate = 15.00
    endif
elseif shipMethod = "Fedex Ground"
    Rate = 6.00
elseif shipMethod = "Fedex 2nd Day"
    Rate = 9.00
elseif shipMethod = "Fedex Overnight"
    if Weight > 12
        Rate = 75.00
    elseif Weight > 6
        Rate = 55.00
    elseif Weight > 3
        Rate = 40.00
    else
        Rate = 20.00
    endif
else
    Rate = 25.00
endif
message "Shipping rate is "+Rate

Just make sure that the if-endif statements are matched up and you can nest as many levels deep as you want.

Note: The if-elseif-else-endif statements are very similar to the case defaultcase endcase statements. However, if-elseif-else-endif statements can be nested, while case statements cannot. The case statement is primarily included for compatibility with older Panorama versions. For new procedures we recommend that you use if-elseif-else-endif statements.


Error Messages

IF or ELSE without ENDIF – Each ELSEIF statement must be paired with a corresponding ENDIF statement. If this error message appears, the necessary endif statement has not been included.

ELSEIF does not have a matching IF statement – Each ELSEIF statement must be paired with a corresponding IF statement. If this error message appears, the necessary if statement has not been included.


See Also


History

VersionStatusNotes
10.0NewNew in this version.