× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Isn't the rule really: "Do from the inside out, starting on the left." ? 
 
 
---------------------------------------------------------
Booth Martin   http://www.MartinVT.com
Booth@xxxxxxxxxxxx
---------------------------------------------------------
 
-------Original Message-------
 
From: RPG programming on the AS400 / iSeries
Date: Thursday, March 20, 2003 13:42:59
To: RPG programming on the AS400 / iSeries
Subject: RE: Operation Precedence questions
 
By that logic, shouldn't and AND & OR operators occur higher in the order of
precedence than the 
=, <>, >, >=, <, & <= operators?

- Dan

--- Bob Cozzi <cozzi@xxxxxxxxx> wrote:
> You also have to consider that the evaluation STOPS when the condition
> cannot be met. So if I=0 the ARRAY(I)>10 comparison is never performed.
> Hence, it works.
> 
> Bob Cozzi
> 
> -----Original Message-----
> From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
> On Behalf Of Dan
> Sent: Thursday, March 20, 2003 11:36 AM
> To: rpg400-l@xxxxxxxxxxxx
> Subject: Operation Precedence questions
> 
> 
> I have a question about Operation Precedence in RPG-IV. FWIW, v5r2. I have
> found the chapter on Expressions in the Reference and, specifically, the
> sections titled "Operation Precedence" and "Short Circuit Evaluation".
Upon
> my brief foray into these topics, it appears to me that the two sections
> permit a contradiction to the rules they set forth.
> 
> "Operation Precedence" says:
> 
> The precedence of operations determines the order in which operations are
> performed within expressions. High precedence operations are performed
> before lower precedence operations.
> 
> The following list indicates the precedence of operations from highest to
> lowest:
> 1. ()
> 2. Built-in functions, user-defined functions
> 3. unary +, unary -, NOT
> 4. **
> 5. *, /
> 6. binary +, binary -
> 7. =, <>, >, >=, <, <=
> 8. AND
> 9. OR
> 
> "Short Circuit Evaluation" says:
> 
> 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.
> 
> <my comments/questions follow>
> 
> If AND & OR are always the lowest precedence, how can the array index
> example above work? 
> According to the rules of precedence, as I interpret them, all of the
> operands:
> I<=%ELEM(ARRAY) 
> I>0 
> ARRAY(I)>10
> would be evaluated before the AND relational operators. If 'I' is zero, I
> would expect a run-time error on the ARRAY(I)>10 because the > operator
has
> a higher precedence than the AND operator.
> 
> BTW, I know from experience that this example works. I am questioning
> whether the precedence of operations really should be re-arranged to place
> AND & OR higher in the list.
> 
> - Dan

__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.

. 

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.