From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,459feef56669b92d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-03 17:23:57 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!intern1.nntp.aus1.giganews.com!nntp.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 03 Nov 2003 19:23:56 -0600 Date: Mon, 03 Nov 2003 20:23:55 -0500 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: "continue/next" for "loop" References: <%txpb.5381$qh2.2068@newsread4.news.pas.earthlink.net> In-Reply-To: <%txpb.5381$qh2.2068@newsread4.news.pas.earthlink.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.34.214.193 X-Trace: sv3-kvcQcouy3OZCQzAQR1Y4dGZjj07lj8xz0AWpQ82KoCUHF+m9YWeF+rumAbgoSuD4l2DSFjdNz2yvaGP!etGQ9wGseDJk7bYRtcrAfNXdD9cnOOrvd7mPB42bNEsYEtC7DcYUeo2Ok4bPnw== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:2017 Date: 2003-11-03T20:23:55-05:00 List-Id: Jeffrey Carter wrote: >> goto exit; -- exit innermost enclosing loop. >> exit loop; -- alternative syntax. ;-) > > > This already exists in Ada; it's syntax is > > exit; > > Without a loop name or when part, exit exits the innermost enclosing loop. Correct. I often use "exit when." Actually for the type of cases discussed here, I often write the loop as an inlined procedure or function and use a return statement for premature loop termination. (As an example, walking an AVL tree looking for a particular key. The return takes care of all the complex nesting issues that can occur.) The goto exit was proposed as "syntactic sugar," since I often see programmers using gotos where exit would do the job. I thought "exit loop" was rubbing the sarcasm in even with the smiley. I have too many times been asked how can I exit a loop. So I thought it was obvious I was being sarcastic. (Maybe I should have said: exit [loop_name]; -- alternative syntax. ;-) Incidently, I the problem which results in exit statements being overlooked is classes that teach for loops, then while loops and maybe eventually get around to: loop ... exit when Done; ... end loop; If you teach students about the general purpose loop first, then add for and while loops as special cases, maybe students will remember. I have no problem. In the first Ada compiler I worked on, while loops were parsed exactly as if they said "loop exit when not ; end loop;" No reason to generate extra work for semantic analysis when we could eliminate some constructs in the parser by translating them into token streams with identical meanings. As for the horrible example that started this thread, I have often had to deal with this type of twisted loop in parsing. Often the best solution is instead of using two for loops use one plain loop, and make incrementing the loop variables explicit. Sometimes that gets too heavy and you really do have to go to named states with gotos. > procedure t is > begin > for j in 2 .. 8 loop > for i in 2 .. 8 loop > if i mod j = 0 then -- Assume complex statements here. > goto next; -- In my real case, it's another loop, > end if; -- which detects the end of current path inside. > Put(i'Img); > <> null; > end loop; > New_Line; > end loop; > end t; procedure t is begin for j in 2 .. 8 loop for i in 2 .. 8 loop if i mod j = 0 then -- Assume complex statements here. exit; else Put(i'Img); end if; end loop; New_Line; end loop; end t; Which in part was why I thought this was another case of "Help! I'm stuck inside a loop and can't get out." -- Robert I. Eachus 100% Ada, no bugs--the only way to create software.