Behaviour of OR statement with NEXT instruction

Belias
Member Posts: 2,998
IF TBSalesLine.FINDSET THEN BEGIN REPEAT IF … then begin IF TBSalesLine.Quantity <> 0 THEN BEGIN .. TFLineMod2 := TRUE; END; END ELSE BEGIN … TFLineMod2 := TRUE; END; IF TFLineMod2 THEN INTSetLineNo2 := TBSalesLine."Line No."; UNTIL TFLineMod2 OR (TBSalesLine.NEXT=0); END;Does the NEXT statement occurs if the TFLineMode2 is true?
my colleague on nav40 said yes, but i'm pretty sure that does not happen in nav2009 (i can't find the code, but i've had to revert the condition to make my code work)
0
Answers
-
Belias wrote:
IF TBSalesLine.FINDSET THEN BEGIN REPEAT IF … then begin IF TBSalesLine.Quantity <> 0 THEN BEGIN .. TFLineMod2 := TRUE; END; END ELSE BEGIN … TFLineMod2 := TRUE; END; IF TFLineMod2 THEN INTSetLineNo2 := TBSalesLine."Line No."; UNTIL TFLineMod2 OR (TBSalesLine.NEXT=0); END;
Does the NEXT statement occurs if the TFLineMode2 is true?
my colleague on nav40 said yes, but i'm pretty sure that does not happen in nav2009 (i can't find the code, but i've had to revert the condition to make my code work)
Hi
Yes, it will occur because Navision resolve every statement of a boolean condition, even if first statement is false and implicity the result will be false.
You can test this with a small program:IF FALSE AND ResultFalse THEN MESSAGE('Final result true') ELSE MESSAGE('Final result false');
resultfalse is a function like:ResultFalse() : Boolean message('ResultFalse checked'); EXIT(FALSE);
If navision does a complete calculation, it will show "ResultFalse checked" message.
If navision will exit immediately at the first statement ("false"), wil not display the message.
On Nav2009Sp1 Classic, i see the "ResultFalse checked" message.
Bye
MatteoReno Sistemi Navision Developer0 -
AND condition means that all the "factors" have to be checked.
OR condition implies that if the first condition is ok, the second one is not executed at all (in C# works like this, but if i'll find the code i wrote in NAV i'll post it)0 -
Belias wrote:AND condition means that all the "factors" have to be checked.
OR condition implies that if the first condition is ok, the second one is not executed at all (in C# works like this, but if i'll find the code i wrote in NAV i'll post it)
Hi
If you change my test like :IF TRUE OR ResultFalse THEN MESSAGE('Final result true') ELSE MESSAGE('Final result false');
"ResultFalse" function will be called even if the first statement is TRUE and there isn't reason to check the second statement.
MatteoReno Sistemi Navision Developer0 -
Belias wrote:AND condition means that all the "factors" have to be checked.
OR also can imply that all factors must be checked - for example: FALSE OR FALSE OR FALSE OR something.
It has nothing to do with how NAV checks logical conditions. As you were told, and checked on your own NAV always checks all part of logical expression.
That's why I never write code like this example:IF someboolean AND someotherboolean AND somerecord.GET(...) THEN
but in such a case always like this:IF someboolean AND someotherboolean THEN IF somerecord.GET(...) THEN
This warrants that fastest conditions are checked first, and GET is executed in latest step.Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Belias wrote:AND condition means that all the "factors" have to be checked.
OR condition implies that if the first condition is ok, the second one is not executed at all (in C# works like this, but if i'll find the code i wrote in NAV i'll post it)
It was not correct in Pascal (C/AL is based on Pascal) and there were compiler options in Pascal to enable the "partial condition evaluation" or how it was named to work in this way...0 -
Slawek Guzek wrote:...It has nothing to do with how NAV checks logical conditions. As you were told, and checked on your own NAV always checks all part of logical expression.
[...]
That's why I never write code like this example:IF someboolean AND someotherboolean AND somerecord.GET(...) THEN
but in such a case always like this:IF someboolean AND someotherboolean THEN IF somerecord.GET(...) THEN
This warrants that fastest conditions are checked first, and GET is executed in latest step.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions