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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56c32e2629d629a X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: What's syntax for a case statement? Date: 1997/06/12 Message-ID: <01bc7729$ea8dfe70$928871a5@dhoos>#1/1 X-Deja-AN: 247864232 Distribution: world References: <5nk6gu$gbp@prometheus.acsu.buffalo.edu> <5nllti$lgb@zdi.informatik.uni-stuttgart.de> <33A0B0BE.30A8@dynamite.com.au> Organization: interQuest Online Services -- Huntsville, AL Newsgroups: comp.lang.ada Date: 1997-06-12T00:00:00+00:00 List-Id: Hi Alan, Just a small nit, but in your case statement syntax definition would be more nearly correct if it said -- e.g., a function call returning a discrete value. David C. Hoos, Sr., Alan Brain 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 => ; > when | => ; > when .. => ; > [when others => ; > 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 => > when 3 | 5 => > when 6 => > when others => > 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 > > >