From: robin on 26 Apr 2010 20:30 "Ali Karaali" <alicpp(a)gmail.com> wrote in message news:dda9d933-e9c1-418f-b62a-bc30bd1dd16c(a)r27g2000yqn.googlegroups.com... |I use goto to break nested for loops and I can't see a | reason to ban goto. Many languages provide a means of leaving loops prematurely, and without the need to use GO TO. PL/I, for instance, provides the LEAVE statement. To skip the remainder of the statements in a loop and to begin another iteration of the loop, PL/I provides an ITERATE statement. In both cases, you don't need to go looking for the label where a GOTO might transfer control.
From: robin on 26 Apr 2010 20:39 "Alexei A. Frounze" <alexfrunews(a)gmail.com> wrote in message news:aab23e01-b4d4-44c4-a136-a619da00a3f7(a)m24g2000prc.googlegroups.com... >I wish there were distinct breaks for loops and switches as well as >multi-level breaks for nested loops. goto's at times are the least >evil since they don't require you to implement extra variables to >break out of nested loops But they do require the introduction of additional labels. As well, you have to go looking for the place where the GOTO transfers. Using a structured method (such as LEAVE in PL/I) makes it obvious that the end of a particular loop is where control resumes. > and they help to simplify function cleanup >code (where resources are being freed on various conditions).
From: bartc on 27 Apr 2010 06:04 "robin" <robin51(a)dodo.com.au> wrote in message news:4bd63021$0$23073$c30e37c6(a)exi-reader.telstra.net... > "Ali Karaali" <alicpp(a)gmail.com> wrote in message > news:dda9d933-e9c1-418f-b62a-bc30bd1dd16c(a)r27g2000yqn.googlegroups.com... > |I use goto to break nested for loops and I can't see a > | reason to ban goto. > > Many languages provide a means of leaving loops > prematurely, and without the need to use GO TO. > PL/I, for instance, provides the LEAVE statement. > > To skip the remainder of the statements in a loop > and to begin another iteration of the loop, > PL/I provides an ITERATE statement. > > In both cases, you don't need to go looking for the > label where a GOTO might transfer control. I use a language which uses 4 control statements to exit or reiterate a loop: restart Re-start the whole loop redo Repeat this iteration next Next iteration exit Exit (Break) completely (by-passing any else-part) (Some loops can have a else-part which is executed on normal exit of the loop, but is skipped when exit is used.) These all work with nested loops, and are in addition to return, stop, and goto. Of course if all seven controls appeared within each level of multiply-nested loops, it would look chaotic. The idea is that these controls are used sensibly and sparingly. Goto itself I mostly use in switch/case statements, where code is shared. For example, if cases X,Y,Z first do A,B,C respectively, but then they all do D. Or they all do P, but then do Q,R,S respectively. I'm still working on a tidy way of representing this without goto, and without putting the common code in a function (which is often inappropriate, troublesome, inefficient and less readable). -- Bartc
From: Richard Bos on 27 Apr 2010 07:16 James Dow Allen <jdallen2000(a)yahoo.com> wrote: > PS: Your newswriter seems to have clipped the link, Daniel, which > I then had to hand-enter. I think Google Groups would have gotten > it right, so you may want to switch to that: :-) > > http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_= > Harmful.html Except, of course, that it doesn't. Quoted-illegible: Just Say No. Richard
From: Richard Bos on 27 Apr 2010 10:07
James Kanze <james.kanze(a)gmail.com> wrote: > In other words, if goto makes the code simpler, it means that > you haven't found the correct expression of the algorithm. > > And of course, the problem isn't with goto, per se. It's with > the way it is used. Those two statements are in contradiction. And that says all you need to know about the argument that "goto is eeeevviiiillll!!!!!" Sheesh, next thing someone'll want to ban it "for the sake of our chiiillldruuuunnn!!!!" Richard |