From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: What's syntax for a case statement?
Date: 1997/06/12
Date: 1997-06-12T00:00:00+00:00 [thread overview]
Message-ID: <01bc7729$ea8dfe70$928871a5@dhoos> (raw)
In-Reply-To: 33A0B0BE.30A8@dynamite.com.au
Hi Alan,
Just a small nit, but <name-of-a-descrete variable> in your case statement
syntax definition would be more
nearly correct if it said <discrete-expression> -- e.g., a function call
returning a discrete value.
David C. Hoos, Sr.,
Alan Brain <aebrain@dynamite.com.au> wrote in article
<33A0B0BE.30A8@dynamite.com.au>...
> Wolfgang Gellerich wrote:
> >
> > In article <5nk6gu$gbp@prometheus.acsu.buffalo.edu>,
sbmoore@cs.buffalo.edu (Scott B Moore) writes:
> > |> I'm new to Ada and I can't find the syntax for a case statement.
Any help?
> >
> > Probably, you will need an introduction/ description of Ada - try
"Programming
> > in Ada95" by John Barnes.
>
> I agree, it's an excellent book, one I'd highly recommend. I've been
> using Barnes' "Programming in Ada" for many years, both to teach, and as
> a reference for rarely-used constructs and predefined specifications.
>
> BTW, the syntax is
>
> case < name-of-a-descrete variable> is
> when <selection1> => <sequence of statements>;
> when <selection2> | <selection3> => <sequence of statements>;
> when <selection4>..<selection5> => <sequence of statements>;
> [when others => <sequence of statements>;
> end case;
>
> Examples:
> Assuming you have
> type TRAFFIC_LIGHT_TYPE is (Red,Green,Amber);
> and a variable
> ONCOMING_LIGHTS : TRAFFIC_LIGHT_TYPE;
>
> then you could have
>
> case ONCOMING_LIGHTS is
> when Red | Amber => STOP(THE_CAR);
> when Green =>
> if ALREADY_STOPPED(THE_CAR) then
> START(THE_CAR);
> end if;
> end case;
>
> or
>
> case ONCOMING_LIGHTS is
>
> when Green =>
> if ALREADY_STOPPED(THE_CAR) then
> START(THE_CAR);
> end if;
>
> when others => STOP(THE_CAR);
>
> end case;
>
> Other examples:
> ThisLetter : CHARACTER;
>
> case ThisLetter is
> when 'a'..'z' => CHANGE_TO_UPPERCASE(ThisLetter);
> when others => null;
> end case;
>
> ThisInteger : INTEGER;
>
> case ThisInteger is
> when -37..2 => <sequence of statements>
> when 3 | 5 => <some other sequence of statements>
> when 6 => <yet another sequence of statements>
> when others => <and the default sequence of statements>
> end case;
>
> OK?
> --
> aebrain@dynamite.com.au <> <> How doth the little Crocodile
> | Alan & Carmel Brain| xxxxx Improve his shining tail?
> | Canberra Australia | xxxxxHxHxxxxxx _MMMMMMMMM_MMMMMMMMM
> 100026.2014 compuserve o OO*O^^^^O*OO o oo oo oo oo
> By pulling MAERKLIN Wagons, in 1/220 Scale
> See http://www.z-world.com/graphics/z/master/8856.gif for picture
>
>
>
prev parent reply other threads:[~1997-06-12 0:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-06-10 0:00 What's syntax for a case statement? Scott B Moore
1997-06-10 0:00 ` John G. Volan
1997-06-10 0:00 ` Michael F Brenner
1997-06-11 0:00 ` Darren C Davenport
[not found] ` <5nllti$lgb@zdi.informatik.uni-stuttgart.de>
1997-06-12 0:00 ` Alan Brain
1997-06-12 0:00 ` Robert Dewar
1997-06-13 0:00 ` Alan Brain
1997-06-13 0:00 ` Robert Dewar
1997-06-12 0:00 ` David C. Hoos, Sr. [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox