How to stop current iteration of loops in navision

mdsr
Member Posts: 163
can we use break statement please give example if any
thanks in advance.
thanks in advance.
0
Best Answer
-
There BREAK command which would let you break out of the loop does not exist as a separate command in C/AL, but you can code around it:
FOR i := 1 TO 100 DO BEGIN // option 1: IF MyExitCondition = TRUE THEN EXIT; //this exits the function, not only the loop. so be careful // option 2: IF MyExitCondition THEN i := 101; //code after this statement will still be executed, but not then next loop iteration END;
For REPEAT ... UNTIL loop you can use something like this:If aRec.FINDSET THEN REPEAT IF MyExitCondition THEN EndOfLoop := TRUE; ELSE EndOfLoop := aRec.NEXT = 0 UNTIL EndOfLoop;
Third possible alternatie (although I don't recommend using it) is to put your code in a report based on the Integer table, let the report to do the looping and use CurrReport.BREAK.
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035
Answers
-
There BREAK command which would let you break out of the loop does not exist as a separate command in C/AL, but you can code around it:
FOR i := 1 TO 100 DO BEGIN // option 1: IF MyExitCondition = TRUE THEN EXIT; //this exits the function, not only the loop. so be careful // option 2: IF MyExitCondition THEN i := 101; //code after this statement will still be executed, but not then next loop iteration END;
For REPEAT ... UNTIL loop you can use something like this:If aRec.FINDSET THEN REPEAT IF MyExitCondition THEN EndOfLoop := TRUE; ELSE EndOfLoop := aRec.NEXT = 0 UNTIL EndOfLoop;
Third possible alternatie (although I don't recommend using it) is to put your code in a report based on the Integer table, let the report to do the looping and use CurrReport.BREAK.
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035 -
The BREAK command has existed in C/AL for some time now. See https://docs.microsoft.com/en-us/dynamics-nav/c-al-break-statement.0
-
@jreynolds please read my response, and read the documentation you posted again, and again. And again.
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031
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