Data editing > Expressions > Logical expressions > Combining logical expressions
 
Combining logical expressions
Quick reference
To combine logical expressions, type:
expression operator expression
where operator is one of:
.or.
.and.
.xor.
More information
Two or more logical expressions may be combined into a single expression using the operators:
.and.
Both/all true
.or.
One or the other or both/all true
.not.
Negates (reverses) an expression
Any number of subexpressions may be combined to form a larger expression, but whether the result is true or false depends upon the values of the subexpressions and also upon the operators used to combine them.
The .and. operator requires that all the expressions preceding and following the .and. be true for the whole expression to be true. Thus, the statement:
int1.eq.9 .and. c116'1'
is true if the integer variable int1 has a value of 9 and column 116 contains a 1. If either subexpression is false, the whole expression is false too.
By comparison, the .or. operator requires that one expression or the other, or both, be true in order for the whole expression to be true.
c(249,251)=$159$ .or. numb(c132,c135) .gt. 4
For this expression to be true, columns 249 to 251 must contain nothing but a ‘1’, ‘5’ and ‘9’ respectively or the number of codes in columns 132 to 135 must be greater than 4. It is also true if both expressions are true. However, if both are false, the overall result is false.
Expressions are reversed (negated) by preceding them with the keyword .not. Although it is not wrong to use it with a single variable, it is more generally used to reverse an expression containing the keywords .and. and .or. Thus, it is not wrong to write .not.c15’1/5’, but it is simpler to write this as c15n’1/5’.
Note Take care when using .not. with the .eq. operator. Statements of the form:
.not. c(1,3) .eq. 100
are incorrect and do not work. Write them as either:
(.not.(c(1,3).eq.100))
with the expression to be reversed enclosed in parentheses, or, more efficiently, as:
(c(1,3).ne.100)
Any of the operators .and., .or., and .not. may appear in a statement more than once, as long as you use parentheses to define the order of evaluation.
Example
(c15'1/47' .or. c16'3579') .and. c22'&'
causes Quantum to check whether the .or. condition is true before dealing with the .and. Suppose the data is:
----+----2----+
    13 &
    79
The first expression (c15’1/47’) is true because column 15 contains a 1 and a 7 and the second expression (c16’3579’) is also true since the codes it contains are amongst those listed as acceptable. Thus, the .or. condition is true. Column 22 contains an ampersand so the last expression is also true, therefore the expression as a whole is true regardless.
If both expressions in the parentheses were false, the whole expression would be false.
See
.not. with .and. and .or.
See also
Logical expressions