|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Anonymous Guest
|
Posted: Wed Aug 16, 2006 10:36 am Post subject: IF-statements with AND conditions |
|
|
Hi,
Consider the following:
IF (A1.AND.A2.AND.A3.AND.A4) THEN
<coding>
END IF
Is it so that all four conditions are evaluated before processing is continued?
Or is the testing stopped after the first condition which results in a FALSE?
And, if so, is the IF-condition evaluated left-to-right or vice versa, or compiler dependent?
And would it be better (for efficiency and speed) to code the statement as
IF (A1) THEN
IF (A2) THEN
IF (A3) THEN
IF (A4) THEN
<coding>
END IF
END IF
END IF
END IF
Kind regards, Lucas. |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Wed Aug 16, 2006 9:40 pm Post subject: IF-statements with AND conditions |
|
|
Assuming A1 - A4 are logical expressions, it is my understanding of the standard is that you can not assume any order of the evaluation of A1, A2, A3 or A4.
This has the associated problem, that if any of A1 thru A4 contain functions, whose evaluation may change other variables, that you can not guarantee which, if any, will be evaluated.
The correct way to code would be as you have indicated by explicitly defining the order.
If A1..A4 are merely logical variables, then the order is irrelevant. To me, the programming efficiency of ordering variables A1..A4, based on their likely true/false value is an insignificant issue.
Regards |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7928 Location: Salford, UK
|
Posted: Thu Aug 17, 2006 12:29 am Post subject: IF-statements with AND conditions |
|
|
I think that John has this right. You can see what FTN95 actually does by looking at the /explist for the code (i.e. /explist on the command line for FTN95) but if you want portable code you cannot assume an order of evaluation. The order may also vary depending upon the level of optimisation used when compiling.
Incidentally speed is not an issue here. The resulting assembly code is probably identical in the two approaches. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|