Breaking Loops

bbrown
Member Posts: 3,268
You can break a loop by placing the loop in its own function and using an EXIT statement within the loop.
There are no bugs - only undocumented features.
0
Comments
-
That's great to hear, but it is kind of abstract. Could you post a code sample?0
-
Example:
Record1 = Global Rec Variable
IF BreakTest THEN BEGIN...(Use Record1)
Function BreakTest : Boolean
IF Record1.FINDSET(TRUE, FALSE) THEN
REPEAT
IF (Condition True) THEN
EXIT(TRUE);
UNTIL Record1.NEXT = 0;
EXIT(FALSE);
There are no bugs - only undocumented features.0 -
That's a good idea and a different approach. For straightforward loop breaking though I prefer an additional boolean variable inside the loop:
IF MyRec.FINDSET THEN BEGIN LeaveTheLoop := FALSE; // don't really need this, since FALSE is default boolean value // but I like to program explicitly REPEAT // do the code here IF Condition Met THEN LeaveTheLoop := TRUE; UNTIL (MyRec.NEXT = 0) OR LeaveTheLoop; END;
0 -
DenSter
I think bbrown solution solves another problem that your code will not. and that is the current record that MyRec will point once the function has existed.
In your code MyRec will point to the next record, while bbrown code the record will point the current record he is comparing to.
makes sense?0 -
Denster,
I think both of the approaches have their applications. I would probably refer to your approach (not to get picky) as Terminating a Loop as it will process a loop iteration in its entirety and determine at the end whether or not to continue the loop. This may not be significant in a small loop but could have an impact in a large loop.
By small vs. large I am referring to the number of commands in the loop and not the size of the record set.There are no bugs - only undocumented features.0 -
ara3n wrote:DenSter
I think bbrown solution solves another problem that your code will not. and that is the current record that MyRec will point once the function has existed.
In your code MyRec will point to the next record, while bbrown code the record will point the current record he is comparing to.
makes sense?0 -
bbrown wrote:Denster,
I think both of the approaches have their applications. I would probably refer to your approach (not to get picky) as Terminating a Loop as it will process a loop iteration in its entirety and determine at the end whether or not to continue the loop. This may not be significant in a small loop but could have an impact in a large loop.
By small vs. large I am referring to the number of commands in the loop and not the size of the record set.0 -
C/Side could really use a GoTo command.There are no bugs - only undocumented features.0
-
bbrown wrote:C/Side could really use a GoTo command.0
-
GoTo are horrible and make the system complicated to follow. That's what I remember from my cs classes.0
-
Please, no GOTO and GOSUB... it is not command for structured language... it was used in Basic where you had no procedures and functions (I am not talking about Visual Basic but about old simple Basic used on 8bit computers as Atari etc.)... And of course in Assembler (JNZ,JZE,JMP etc.)0
-
I concur: no GOTO's. They create, what is called spaghetti-programs. You know where your program starts, but not where it goes and even less where it ends.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
kriki wrote:I concur: no GOTO's. They create, what is called spaghetti-programs. You know where your program starts, but not where it goes and even less where it ends.No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)0
-
Luc Van Dyck wrote:kriki wrote:I concur: no GOTO's. They create, what is called spaghetti-programs. You know where your program starts, but not where it goes and even less where it ends.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Luc Van Dyck wrote:And you, Italians, are very good at it ... the spaghetti I mean
very funny Luc
0 -
DenSter wrote:Luc Van Dyck wrote:And you, Italians, are very good at it ... the spaghetti I mean
very funny Luc
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!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