Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

how does the evaluation of the <condition> in an IF-statement work?

chwizgl
2020-02-09
2020-02-20
  • chwizgl - 2020-02-09

    I'm looking for runtime optimizations and have the following problem, which I can't find any answer to in the documentation:

    Let's assume, I have multiple conditions for an IF-statement, e.g.

    var1 := FALSE;
    var2 := (whatever);
    IF var1 AND var2 THEN
    Β  Β  ; // some code
    END_IF
    

    Is ```

    var1 AND var2

    evaluated in any case? or does it abort the evaluation as soon as it sees that

    var1 = FALSE

    ```?

    Reason: Before I evaluate a complex IF-condition (var2), I would like to pre-check, if this is necessary (var1). The second condition is expensive but is not required in 99% of the cases.

    PS: Does anybody have a collection of such runtime optimization hints?

     
  • chwizgl - 2020-02-11

    Thanks a lot!

    For the sake of completeness let's mention that for the OR statement there is also a corresponding OR_ELSE statement

     
  • jan233321 - 2020-02-20

    +1 to list of FAQ of efficient runtime optimization in Codesys V3! Because the compiler is doing almost nothing in term of code efficiency...

     

Log in to post a comment.