Mike Torrettinni 198 Posted April 5, 2019 I just wanted to share that after 15+years of Delphi, today I used repeat until for the first time! 🙂 I scanned my code and in all 100Ks of lines of code not once I used it on my own (I did find it in some methods that I'm not original writer). Actually feels good, as I never found the real use for it, always just For or While.  And the reason I used it is because I had a simple loop for which I wasn't sure when it will end, so I didn't think about all conditions - which would be the case to use While loop and pre-setting all conditions at the beginning. So, here is my first real use case for repeat until: // Add Parents in reversed order repeat Result := [aNode.ParentNode] + Result; aNode := aNode.Parent; until (aNode.ParentNode = nil) or (aNode.ParentNode.NodeType = ntDocument) or (aNode.ParentNode.NodeLevel = 0); Here I was allowed to add conditions at the end, since I didn't know all of them at the beginning. And it became this beauty of 4 lines 🙂  Happy day! 🙂 1 Share this post Link to post
FredS 138 Posted April 5, 2019 17 minutes ago, Mike Torrettinni said: first time  Used my first 'goto' a couple of weeks ago 🙂 1 1 Share this post Link to post
Rollo62 536 Posted April 5, 2019 then also try out "while .. do" loops, they can replace for and repeat loops both Share this post Link to post
Stefan Glienke 2002 Posted April 5, 2019 9 hours ago, FredS said: Used my first 'goto' a couple of weeks ago I was tempted yesterday to use it until I figured out how to get the same result (also codegen wise with as little jumps as possible) using loops in a kinda readable way. 😉 Share this post Link to post
dummzeuch 1505 Posted April 5, 2019 (edited) If you have never used a goto, you have never written complex code. 😉  (I usually prefer Exit over goto, but Exit is also considered evil.) Edited April 6, 2019 by dummzeuch Share this post Link to post
A.M. Hoornweg 144 Posted April 5, 2019 I rarely ever use repeat either. Because a repeat loop always iterates at least once. The example of the original poster will throw a GPF if the initial node is the root node.   I do use exit() , but if it is inside a try/finally block, I always write a remark behind it that it will jump to the next "finally" statement.   Share this post Link to post
Mike Torrettinni 198 Posted April 5, 2019 10 minutes ago, A.M. Hoornweg said: GPF GPF? Share this post Link to post
FredS 138 Posted April 5, 2019 3 hours ago, Stefan Glienke said: loops in a kinda readable way.  I was adding something to a tested function and the only way I could justify not retesting all of it is by using 'goto'.. Share this post Link to post
Bill Meyer 337 Posted April 5, 2019 1 hour ago, Mike Torrettinni said: GPF? General Protection Fault. An exception, and a term not often seen in current discussions. 1 Share this post Link to post
Mike Torrettinni 198 Posted April 5, 2019 26 minutes ago, Bill Meyer said: General Protection Fault. An exception, and a term not often seen in current discussions. Thanks, don't remember last time I saw this. Share this post Link to post
Guest Posted April 5, 2019 Exit is brilliant in fuctions. Otherwise, i tend to agree it's a bit finicky. I like repeat for some special cases. But every time i did a repeat it was to get rid of some local vars needed in a while. Repeat IMHO should require a begin-end block IMHO to be consistent with the other program control keywords. Share this post Link to post
Guest Posted April 5, 2019 (edited) I remember when i was able to use labels for goto instead of only line numbers. WOW - that was a LEAP forward! I think the language was CBasic and the OS was CP/M. Edited April 5, 2019 by Guest Added compiler and OS. Share this post Link to post
Bill Meyer 337 Posted April 5, 2019 20 minutes ago, Dany Marmur said: Exit is brilliant in fuctions. Otherwise, i tend to agree it's a bit finicky. I like repeat for some special cases. But every time i did a repeat it was to get rid of some local vars needed in a while. Repeat IMHO should require a begin-end block IMHO to be consistent with the other program control keywords. Exit, Break, and Continue all seem to me to be structured GOTOs. They interrupt the flow, but in a well ordered way. Well, at least when used properly, it is well ordered. 1 Share this post Link to post
Bill Meyer 337 Posted April 5, 2019 20 minutes ago, Dany Marmur said: I think the language was CBasic and the OS was CP/M. If we discuss having used those, we date ourselves. 😉 I still have my TP1 for Z80 manual. Share this post Link to post
Esteban Pacheco 16 Posted April 6, 2019 In functions "Exit(Boolean)" is the best. My goto statement to match a "return" on C# and exit quickly on condition.   Share this post Link to post
Mike Torrettinni 198 Posted April 6, 2019 I do the same, use Exit a lot of times to exit quickly with result, no matter what type, boolean, string and integer. 1 Share this post Link to post
Rudy Velthuis 91 Posted April 6, 2019 On 4/5/2019 at 4:07 PM, Mike Torrettinni said: GPF? General Protection Fault. Â He should have four stars, by now. 1 Share this post Link to post
Rudy Velthuis 91 Posted April 6, 2019 (edited) On 4/5/2019 at 5:14 PM, Bill Meyer said: General Protection Fault. An exception, and a term not often seen in current discussions. Probably because GPF is called Access Violation (AV) on Windows. Edited April 6, 2019 by Rudy Velthuis Share this post Link to post
Rudy Velthuis 91 Posted April 6, 2019 On 4/5/2019 at 7:15 PM, Bill Meyer said: Exit, Break, and Continue all seem to me to be structured GOTOs. They interrupt the flow, but in a well ordered way. Well, at least when used properly, it is well ordered. So are For, While and Repeat. They are structured GOTOs as well, but with a built-in If. The jump is just hidden a little better. Share this post Link to post
Lars Fosdal 1792 Posted April 8, 2019 The other day, I discovered that you can't use Exit() in a finally section. Needless to say, I had a second go at that code. 1 Share this post Link to post
A.M. Hoornweg 144 Posted April 8, 2019 On 4/5/2019 at 5:14 PM, Bill Meyer said: General Protection Fault. An exception, and a term not often seen in current discussions.  On 4/6/2019 at 9:07 PM, Rudy Velthuis said: Probably because GPF is called Access Violation (AV) on Windows. You're right, that's what it's called nowadays (and it is a much clearer description). Any idea in what OS version Microsoft renamed it? Share this post Link to post
David Schwartz 426 Posted April 8, 2019 3 hours ago, A.M. Hoornweg said:  You're right, that's what it's called nowadays (and it is a much clearer description). Any idea in what OS version Microsoft renamed it? It's still GPF in my mind! I have no idea when they renamed it. IIRC, GPFs were frequently accompanied by BSODs, which still happen every now and then. (I'll let someone ask what they are... ) Share this post Link to post
Bill Meyer 337 Posted April 8, 2019 45 minutes ago, David Schwartz said: It's still GPF in my mind! I have no idea when they renamed it. IIRC, GPFs were frequently accompanied by BSODs, which still happen every now and then. (I'll let someone ask what they are... ) It is still GPF under the covers, as in the Wikipedia article here:https://en.wikipedia.org/wiki/General_protection_fault The jargon comes from the x86 CPU family. The AV term is discussed here:https://en.wikipedia.org/wiki/Segmentation_fault Share this post Link to post
David Schwartz 426 Posted April 8, 2019 (edited) Back to the original topic regarding repeat ... until:  I use them very rarely myself.  I really miss the for statement from C/C++ in Delphi, because it lets you specify the initial condition as well as the test and incrementor all in the same line.  The problem with most loops is you need to do something first to "prime the pump" so to speak, before you can get the while or repeat loop running. A classic one is iterating through the results of a DB query:  qry.Open; . . . qry.First(); while not qry.EOF do begin . . . qry.Next(); end; In C/C++ that could be done as follows:  for (qry.Open; not qry.EOF; qry.Next) { . . . } I think this is much nicer. Edited April 8, 2019 by David Schwartz 1 Share this post Link to post
Mike Torrettinni 198 Posted April 8, 2019 1 hour ago, David Schwartz said: The problem with most loops is you need to do something first to "prime the pump" so to speak, before you can get the while or repeat loop running. Yes... but this time it was a small function so all checks for valid values were already done and just quick loop was needed. I don't even know why I chose Repeat, but it worked out really well. I just hope I will not get too excited and try to force it instead of While 🙂 Share this post Link to post