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;
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?
Ahmed Rashed Amini
Independent Consultant/Developer
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.
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?
Makes sense, but in my code you do what you need to do with the current record inside the loop. If you need to save the current record for after the loop you have other ways to do that. I would not do MyRec.NEXT until *after* I am done with the current record.
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.
It really depends on what you want to do. I've always been able to program an escape, either by adding the exit condition at the end, or write a function to process one record in which you can always add an EXIT statement. I prefer not to give loop control over to another function, unless there's a sub-loop if you know what I mean. You're right though, there's an application for both approaches, and it's a matter of personal style as to what you like, I don't think there's a *right* or *wrong* way to do it, as long as it works
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.)
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!
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.
And you, Italians, are very good at it ... the spaghetti I mean
No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
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.
And you, Italians, are very good at it ... the spaghetti I mean
BTW:I am still Belgian :!: This because a belgian law says that I lose the belgian nationality if I ask for another nationality. Only if the initiative comes from the other country, a belgian keeps also the belgian nationality.
Regards,Alain Krikilion No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Comments
RIS Plus, LLC
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);
RIS Plus, LLC
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?
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
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.
RIS Plus, LLC
RIS Plus, LLC
RIS Plus, LLC
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
RIS Plus, LLC
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!