Page 1 of 1

IF Statement Evaluation in Rules

Posted: Thu Feb 08, 2024 9:53 pm
by 20 Ton Squirrel
Examine the example rule below:

Code: Select all

[ 'Output Value' ] = N:
    IF (  DB ( 'ExampleCubeA' , 'ExampleElementA' ) = 0
        % DB ( 'ExampleCubeB' , 'ExampleElementB' ) = 0
         , 0
         , CONTINUE 
        ) ; 
There are two conditions to be evaluated. If the first condition evaluates FALSE, does the second condition get tested or does the processor bail out?

I'm asking because I'm stuck tracking down circular references. Some rules fit this example where it was assumed the processor bails out the moment a FALSE is evaluated. If the processor evaluates the ENTIRE conditional line, I'll need to rethink these rules.

Re: IF Statement Evaluation in Rules

Posted: Thu Feb 08, 2024 11:05 pm
by ykud
I remember looking into this a while back and concluding that all IF conditions are evaluated, but I can't remember what example I used to conclude this (I think it was looking at rule stats to see if a measure value is being calculated where it shouldn't be). I think the order of how you write A OR B doesn't define order of calculation, e.g. that A should be evaluated before B.

Definitely caused me to rewrite some of the rules at that point and I keep writing them with this assumption since then.

Re: IF Statement Evaluation in Rules

Posted: Fri Feb 09, 2024 7:45 am
by MarenC
Hi,

In some languages I believe the double operator, e.g. && or %%, means only evaluate where necessary, whereas a single means evaluate all results.

As for TM1, I suspect ykud is correct.

Maren

Re: IF Statement Evaluation in Rules

Posted: Fri Feb 09, 2024 2:44 pm
by 20 Ton Squirrel
It was my programming background that led me to assume the processor aborted after a false condition. I should've written these rules more cautiously! I'll scoot the conditions within a nested IF or stagger them into separate IFs with CONTINUE. Thanks for the responses!

Re: IF Statement Evaluation in Rules

Posted: Wed Feb 14, 2024 1:15 pm
by Adam
Short-circuiting is the concept here, and not every language implements that. VBA also does not for those using PAXAPI.