Path: utzoo!utgpu!watserv1!watmath!att!pacbell.com!ucsd!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!news.cs.indiana.edu!noose.ecn.purdue.edu!mentor.cc.purdue.edu!j.cc.purdue.edu!brazil.psych.purdue.edu!zhou From: zhou@brazil.psych.purdue.edu (Albert Zhou) Newsgroups: comp.lang.pascal Subject: Re: Gotos are ok Message-ID: <11724@j.cc.purdue.edu> Date: 25 Jan 91 11:25:53 GMT Sender: news@j.cc.purdue.edu Reply-To: zhou@brazil.psych.purdue.edu (Albert Zhou) Organization: Purdue University Lines: 43 I certainly agree that exit (leave or whatever) is different from goto although you can implement exit with goto. When I posted the original article, I was plagued by the limitation of "exit" implemented on Turbo Pascal. I wanted exit several nested subroutines altogether, but I could find a direct way to do it. Before this posting, I virtually had never touch "goto" in Pascal. Unfortunately I found that goto's couldn't go across modules (subroutines). I had thought that labels declared globally could be refered everywhere just like global variable. As I later realized, global labels can cause disasters for those who use goto at all. To further demonstrate the limitation of exit, please see the following example: Some suggest to implement an exit functioning like break in C, it will work for repeat ... if c then exit until whatever However, for a multiple-loop structure, one should be enabled to exit a specified number of nested blocks: for i := 1 to 2 for j := 1 to 3 do begin ... if c then exit(2) end We also need such kind of exits for subroutines. Sorry I already use the word exit for exiting blocks. So let me use exitsub for this. So exitsub(3) means to exit from level n (current level) to level n-3. If n-3 is negative, it will of course stop after exiting to the top level. This is very useful for error handling procedures. exitsub would be very easy to use and very useful too, as long as your program is structured (I guess most people programming in pascal do write structured programs). For example, one can write exitsub(3) when he/she wants to exit from level 7 to level 4.