Evaluation of boolean expressions in controll statements

mabl4367mabl4367 Member Posts: 143
I have some questions about the evaluation of boolean expressions in controll statements. Lets start with the folowing:

IF (A=B) AND (C=D) THEN;

Are both expressions always evaluated, even if A=B is FALSE?

What if one expression contains a function call:

IF (A=B) AND myRecord.GET(primKeyVal1,primKeyVal2,...) THEN;

Can I always count on GET to be executed or is it only executed if A=B is TRUE?

Comments

  • matteo_montanarimatteo_montanari Member Posts: 189
    mabl4367 wrote:
    I have some questions about the evaluation of boolean expressions in controll statements. Lets start with the folowing:

    IF (A=B) AND (C=D) THEN;

    Are both expressions always evaluated, even if A=B is FALSE?

    What if one expression contains a function call:

    IF (A=B) AND myRecord.GET(primKeyVal1,primKeyVal2,...) THEN;

    Can I always count on GET to be executed or is it only executed if A=B is TRUE?

    Hi

    Navision resolve every statement of a "IF" instruction.
    On your example, the GET method will be executed if A=B and A<>B.

    You can change it like
    IF (A=B) THEN
    IF myRecord.GET(primKeyVal1,primKeyVal2,...) THEN;

    Bye

    Matteo
    Reno Sistemi Navision Developer
  • mabl4367mabl4367 Member Posts: 143
    Thanks a bunch!
  • matttraxmatttrax Member Posts: 2,309
    So for all those former OO programmers out there (me included), short circuiting is not supported...at least I think that's what it was called...wow, it's been a long time.
  • mabl4367mabl4367 Member Posts: 143
    Here is a related question:

    What will this code do?

    CLEAR(myRecord);
    myRecord.INIT();
    myRecord.myFiled:='Hello!'
    myRecord.INSERT();
    primaryKey:=myRecord.primaryKey;
    CLEAR(myRecord);
    IF myRecord.GET(primaryKey) AND (myRecord.myField='Hello!') THEN
    MESSAGE('myRecord.myFiled= %1',myRecord.myField)
    ELSE
    MESSAGE('myRecord: %1 could not be found or the myRecord.myField!=Hello!',primaryKey);

    The question is: Will the evaluation of myRecord.GET(primaryKey) be preformed first and will myRecord contain the newly inserted record when the evaluation of myRecord.myField='Hello!' is preformed?
  • David_SingletonDavid_Singleton Member Posts: 5,479
    mabl4367 wrote:
    I have some questions about the evaluation of boolean expressions in controll statements. Lets start with the folowing:

    IF (A=B) AND (C=D) THEN;

    Are both expressions always evaluated, even if A=B is FALSE?

    What if one expression contains a function call:

    IF (A=B) AND myRecord.GET(primKeyVal1,primKeyVal2,...) THEN;

    Can I always count on GET to be executed or is it only executed if A=B is TRUE?

    No you can not. There is no (official) documentation on this and it is planned to change in the future. So even though it will work in the current version it probably wont in the future.

    There was a very good session at Directions where this was explained. So don't rely on unsupported features.
    David Singleton
  • genericgeneric Member Posts: 511
    I totally agree with above statement.

    But maybe the same could be said about this.

    viewtopic.php?f=23&t=39842&p=195384#p195384
  • David_SingletonDavid_Singleton Member Posts: 5,479
    generic wrote:
    I totally agree with above statement.

    But maybe the same could be said about this.

    viewtopic.php?f=23&t=39842&p=195384#p195384

    How so?
    David Singleton
  • genericgeneric Member Posts: 511
    there is no documentation for it.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    generic wrote:
    there is no documentation for it.

    Wrong... :lol:

    This feature has been in Navision since I started using Navision in the DOS version.

    Go to the property and hit F1 you will see it is fully documented and always has been. \:D/
    David Singleton
Sign In or Register to comment.