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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2cb6c27047140e0 X-Google-Attributes: gid103376,public From: dewarr@my-dejanews.com Subject: Re: How to implement a continue statement in Ada? Date: 1998/09/01 Message-ID: <6sgmk2$6n5$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 386739735 References: <35EA816A.E11FEA85@physics.purdue.edu> <35EB7036.5585@atlas.otago.ac.nz> X-Http-Proxy: 1.0 x6.dejanews.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Tue Sep 01 11:42:57 1998 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/2.02 (OS/2; I) Date: 1998-09-01T00:00:00+00:00 List-Id: In article <35EB7036.5585@atlas.otago.ac.nz>, ok@atlas.otago.ac.nz wrote: > Robert T. Sagris wrote: > > I was wondering if there is a general way of implementing > > the behavior of C's continue statement in Ada. > > > > If at all possible without using a goto statement. > > Will you accept an 'exit'? > > Loop statements can have names (LRM 5.5). > But so can blocks (LRM 5.6). > > The general C form > > for (init; cond; updt) stmt > > can be converted to > > begin > init; > Loop_All: > while cond loop > Loop_Body: > begin > stmt > end; > updt; > end loop > end; > > 'break' => exit Loop_All; > 'continue' => exit Loop_Body; > > Obvious simplifications apply to particular cases. > This is wrong. It is also a good reminder to PLEASE compile what you suggest before you suggest it. I always do (I do not trust my knowledge of Ada to be 100% reliable, especially in the rush of replying to newsgroup articles). The exit statement can ONLY be used to exit from a loop in Ada, it cannot be used to exit from a block in the manner suggested above. If you had compiled your suggestion you would have got an error message similar to k.adb:4:07: invalid loop name in exit statement Note that this also serves as a reminder that you have to be careful reading responses to CLA, do not assume that all posts are technicaly correct. It is possible to replace the block in Richard's example by a dummy loop: Loop_Body : loop ... exit Loop_Body; end Loop_Body; but you really have to be quite allergic to gotos to prefer this to the simple and straightforward use of a goto to achieve a continue. Note also that the syntax in Richard's example is quite wrong (again something that compiling it would have revealed). If a loop or block is named, the name MUST be repeated on the end Robert Dewar -----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum