Time/order of evaluation of expression

CrunchCrunch Member Posts: 38
Hi

I initially made a mistake, when I changed some code, where I wanted to evaluate the UserSetup field values before I went to the next UserSetup record.

Wrong:
REPEAT
  something
UNTIL (UserSetup.NEXT = 0) OR 
          UserSetup."Unlimited Request Approval" OR
          ((ApprovalAmountLCY <= UserSetup."Request Amount Approval Limit") AND
           (UserSetup."Request Amount Approval Limit" <> 0));

(I could also make a boolean inside the "Repeat" evaluating the expression before the "Until", but I would like to know how it works.)

My question is, wether the code below would evaluate the values before moving to the next record?
Correct?
REPEAT
  something
UNTIL UserSetup."Unlimited Request Approval" OR
          ((ApprovalAmountLCY <= UserSetup."Request Amount Approval Limit") AND
           (UserSetup."Request Amount Approval Limit" <> 0)) OR 
          (UserSetup.NEXT = 0);


EDIT: As far as I can see, this seems to work fine. I'll leave the post open a little while, in case someone has something useful to say on the subject.

Answers

  • krikikriki Member, Moderator Posts: 9,112
    Crunch wrote:
    My question is, wether the code below would evaluate the values before moving to the next record?
    Correct?
    Don't count on it. You can't be sure of it. The problem for this case is that NAV does NOT use lazy-evaluation. It evaluates all parts of the expression, but I am not sure in which order it does. Probably from left to right. But I am not sure.

    If I need to do something like this, I use this construct:
    REPEAT
      ContinueLooping := TRUE;
    
      Something;
    
      IF ContinueLooping THEN
        ContinueLooping := (UserSetup.NEXT <> 0);
      IF ContinueLooping THEN
        ContinueLooping := (NOT UserSetup."Unlimited Request Approval");
      IF ContinueLooping THEN
        ContinueLooping := 
          (NOT ((ApprovalAmountLCY <= UserSetup."Request Amount Approval Limit") AND
                   (UserSetup."Request Amount Approval Limit" <> 0)));
    UNTIL (NOT ContinueLooping);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.