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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f813b1b9c8de30d6,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-07 03:50:08 PST Path: supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!newsfeed2.news.nl.uu.net!sun4nl!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: Mario Amado Alves Newsgroups: comp.lang.ada Subject: Getting a one-touch option (was: Ada95 tutorials with sample code) Date: Wed, 7 Mar 2001 11:50:21 +0000 (WET) Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: avanie.enst.fr 983965508 13280 137.194.161.2 (7 Mar 2001 11:45:08 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Wed, 7 Mar 2001 11:45:08 +0000 (UTC) To: "'comp.lang.ada@ada.eu.org'" Return-Path: X-Authentication-Warning: lexis.di.fct.unl.pt: maa owned process doing -bs In-Reply-To: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: supernews.google.com comp.lang.ada:5495 Date: 2001-03-07T11:50:21+00:00 > procedure Xyz is > > opt_is : character := ' '; > > begin > > while opt_is /= 'V' and then opt_is /= 'A' loop > Put( opt_prompt ); > NEW_LINE; > Ada.Text_IO.Put_Line( "Please enter either a 'V' or an 'A' ); > Get( opt_is ); > opt_is := To_Upper(opt_is); > end loop; > > end Xyz; Lately I have been using enumerations and exceptions for this kind of problem: type Options is (A, V); Option: Options; C: Character; begin loop Put("Please enter either a 'V' or an 'A'"); Get_Immediate(C); begin Option := Options'Value(C & ""); exit; exception when Constraint_Error => null; end; end loop; There is of course more to be said about "exception-oriented" programming. Let us save that for the Ada-Europe'2001 workshop ;-) | |,| | | |RuaFranciscoTaborda24RcD 2815-249CharnecaCaparica 351+939354005 |M|A|R|I|O| |A|M|A|D|O|DepartmentoDeInformaticaFCT/UNL 2825-114 Caparica 351+212958536 |A|L|V|E|S| fax 212948541 | | | | | | maa@di.fct.unl.pt FCT 212948300