From: Mario Amado Alves <maa@di.fct.unl.pt>
To: "'comp.lang.ada@ada.eu.org'" <comp.lang.ada@ada.eu.org>
Subject: Getting a one-touch option (was: Ada95 tutorials with sample code)
Date: Wed, 7 Mar 2001 11:50:21 +0000 (WET)
Date: 2001-03-07T11:50:21+00:00 [thread overview]
Message-ID: <mailman.983965508.309.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <B6A1A9B09E52D31183ED00A0C9E0888C469A44@nctswashxchg.nctswash.navy.mil>
> 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
next parent reply other threads:[~2001-03-07 11:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <B6A1A9B09E52D31183ED00A0C9E0888C469A44@nctswashxchg.nctswash.navy.mil>
2001-03-07 11:50 ` Mario Amado Alves [this message]
2001-03-08 18:10 ` Getting a one-touch option (was: Ada95 tutorials with sample code) mcdoobie
2001-03-08 18:49 ` Marin David Condic
2001-03-08 19:21 ` tmoran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox