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.6 required=5.0 tests=BAYES_05,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC 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: Alan Brain Subject: Re: What's syntax for a case statement? Date: 1997/06/12 Message-ID: <33A0B0BE.30A8@dynamite.com.au>#1/1 X-Deja-AN: 247841551 References: <5nk6gu$gbp@prometheus.acsu.buffalo.edu> <5nllti$lgb@zdi.informatik.uni-stuttgart.de> Organization: @Home Reply-To: aebrain@dynamite.com.au Newsgroups: comp.lang.ada Date: 1997-06-12T00:00:00+00:00 List-Id: 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