|
and "or" logic in a condition? I always thought the left to right process
of handling a condition was standard across the board. I'm curious what
these are (and really, why is it different).
lowest:
1. ()
2. Built-in functions, user-defined functions
3. unary +, unary -, NOT
4. **
5. *, /
6. binary +, binary -
7. =, <>, >, >=, <, <=
8. AND
9. OR
But it also has a section on "Order of Evaluation" which says in part:
Therefore, if a variable is used twice anywhere within an expression, andYou must also consider that some languages / compilers do "short circuit
there is the possibility of side effects, then the results may not be the
expected ones.
For example, consider the source shown in Figure 169<http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/books_web/c0925086558.htm#FIGFSIDFX>,
where A is a variable, and FN is a procedure that modifies A. There are two
occurrences of A in the expression portion of the second EVAL operation. *If
the left-hand side (operand 1) of the addition operation is evaluated first
*, X is assigned the value 17, (5 + FN(5) = 5 + 12 = 17). *If the
right-hand side (operand 2) of the addition operation is evaluated first*,
X is assigned the value 18, (6 + FN(5) = 6 + 12 = 18). "
"Relational operations AND and OR are evaluated from left to right.
However, as soon as the value is known, evaluation of the expression stops
and the value is returned. As a result, not all operands of the expression
need to be evaluated.
For operation AND, if the first operand is false, then the second operand
is not evaluated. Likewise, for operation OR, if the first operand is true,
the second operand is not evaluated.
There are two implications of this behaviour. First, an array index can be
both tested and used within the same expression. The expression
I<=%ELEM(ARRAY) AND I>0 AND ARRAY(I)>10
will never result in an array indexing exception.
The second implication is that if the second operand is a call to a
user-defined function, the function will not be called. This is important if
the function changes the value of a parameter or a global variable."
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.