Logical Operators (&&, ||, !)

InstallShield 2020 » InstallScript Language Reference

Logical operators allow you to ask more than one relational question at the same time. For example, using a logical operator you can ask if y is greater than 7 and szFilePath contains “C:\\Program Files\\Company Name”. Logical operators return either a TRUE (1) or FALSE (0) value. Like relational operators, they are used most often in if and while statements.

The InstallScript compiler recognizes the logical operators listed in the table below:

Logical Operators

Symbol

Operation

Example

Description

&&

AND

exp1 && exp2

True only if both exp1 and exp2 are true; otherwise, false.

||

OR

exp1 || exp2

True if either exp1 or exp2 is true; false (0) only if both are false.

!

NOT

!exp1

False if exp1 is true; true if exp1 is false.

Logical operators have a lower precedence than arithmetic or relational operators. Among logical operators, the AND operator has higher precedence than the OR operator.

Caution:Unlike C++, InstallShield performs complete Boolean evaluations of logical expressions. Consider the following if statement:

    if (iVar = 10) && (MyFunction( ) = 0) then

        MessageBox("That is so true.", INFORMATION);

    endif;

MyFunction will be called even if the expression to the left of the logical operator is false. To obtain the effect of short circuit Boolean evaluations (in which the expression to the right of the && is resolved only if the expression to the left of the && is true), use a nested if statement, as shown below:

    if (iVar = 10) then

        if (MyFunction( ) = 0) then

            MessageBox("That is so true.", INFORMATION);

        endif;

    endif;