* What's syntax for a case statement? @ 1997-06-10 0:00 Scott B Moore 1997-06-10 0:00 ` John G. Volan ` (3 more replies) 0 siblings, 4 replies; 9+ messages in thread From: Scott B Moore @ 1997-06-10 0:00 UTC (permalink / raw) I'm new to Ada and I can't find the syntax for a case statement. Any help? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: What's syntax for a case statement? 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 ` (2 subsequent siblings) 3 siblings, 0 replies; 9+ messages in thread From: John G. Volan @ 1997-06-10 0:00 UTC (permalink / raw) Scott B Moore wrote: > > I'm new to Ada and I can't find the syntax for a case statement. Any help? I would think that any good textbook on Ada would have an index in the back with an entry on "case statements" directing you to the proper page. :-) Are you taking a course on Ada at the University of Buffalo? Surely your professor must have assigned you a decent textbook with a good index! :-) If for some reason you don't have such a textbook, never fear, you can consult the online Ada95 Language Reference Manual at http://www.adahome.com/rm95/ The immediate answer to your question is in section 5.4: http://www.adahome.com/rm95/rm9x-05-04.html The syntax notation is not altogether impossible to decipher, and there are a few examples of case statements at the bottom that will give you the idea. However, I don't recommend trying to learn Ada from the RM95. It was designed to be a precise and unambiguous specification of the language, not a tutorial. You can find some good online tutorials, textbook reviews, and many other useful resources at the "Home of the Brave Ada Programmers" web site: http://www.adahome.com/ Good luck to you! ------------------------------------------------------------------------ Internet.Usenet.Put_Signature (Name => "John G. Volan", Employer => "Texas Instruments Advanced C3I Systems, San Jose, CA", Work_Email => "johnv@ti.com", Home_Email => "johnvolan@sprintmail.com", Slogan => "Ada95: World's *FIRST* International-Standard OOPL", Disclaimer => "My employer never defined these opinions, so using " & "them would be totally erroneous...or is that just " & "nondeterministic behavior now? :-) "); ------------------------------------------------------------------------ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: What's syntax for a case statement? 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> 3 siblings, 0 replies; 9+ messages in thread From: Michael F Brenner @ 1997-06-10 0:00 UTC (permalink / raw) truth: constant boolean := weigh_canopic_jar_against_feather_of_Maat; ... case truth is when true => fire_of_dispersion.pass; when false => fire_of_dispersion.dissolve; end case; ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: What's syntax for a case statement? 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> 3 siblings, 0 replies; 9+ messages in thread From: Darren C Davenport @ 1997-06-11 0:00 UTC (permalink / raw) Scott B Moore (sbmoore@cs.buffalo.edu) wrote: : I'm new to Ada and I can't find the syntax for a case statement. Any help? http://www.adahome.com/rm95/rm9x-05-04.html ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <5nllti$lgb@zdi.informatik.uni-stuttgart.de>]
* Re: What's syntax for a case statement? [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-12 0:00 ` David C. Hoos, Sr. 0 siblings, 2 replies; 9+ messages in thread From: Alan Brain @ 1997-06-12 0:00 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: What's syntax for a case statement? 1997-06-12 0:00 ` Alan Brain @ 1997-06-12 0:00 ` Robert Dewar 1997-06-13 0:00 ` Alan Brain 1997-06-12 0:00 ` David C. Hoos, Sr. 1 sibling, 1 reply; 9+ messages in thread From: Robert Dewar @ 1997-06-12 0:00 UTC (permalink / raw) Alan said <<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; >> This is completely wrong, there is no requirement that the expression after the case be the name of a discrete variable, it is a general expression. If you are going to post syntax that can easily be looked up, at least do it right! Also, your style of using examples, rather than proper syntax, for the when phrases is also confusing. It is hard to understand for example that it is fine to have when x | y .. z => ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: What's syntax for a case statement? 1997-06-12 0:00 ` Robert Dewar @ 1997-06-13 0:00 ` Alan Brain 1997-06-13 0:00 ` Robert Dewar 0 siblings, 1 reply; 9+ messages in thread From: Alan Brain @ 1997-06-13 0:00 UTC (permalink / raw) Robert Dewar wrote: > > Alan said > > <<case < name-of-a-descrete variable> is > This is completely wrong, there is no requirement that the expression after > the case be the name of a discrete variable, it is a general expression. > > If you are going to post syntax that can easily be looked up, at least do > it right! I stand corrected, and my thanks. Moral of story: Never, ever, post on a public newsgroup at 3 am, immediately after writing to a student why he couldn't say case NameOfAFloat is when 0.0..3.768 => -- 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: What's syntax for a case statement? 1997-06-13 0:00 ` Alan Brain @ 1997-06-13 0:00 ` Robert Dewar 0 siblings, 0 replies; 9+ messages in thread From: Robert Dewar @ 1997-06-13 0:00 UTC (permalink / raw) <<Moral of story: Never, ever, post on a public newsgroup at 3 am, immediately after writing to a student why he couldn't say >> Well anyone can get syntax wrong at 3 am, although amazingly enough GNAT seems to diagnose syntax errors at any time of day fearlessly :-) :-) ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: What's syntax for a case statement? 1997-06-12 0:00 ` Alan Brain 1997-06-12 0:00 ` Robert Dewar @ 1997-06-12 0:00 ` David C. Hoos, Sr. 1 sibling, 0 replies; 9+ messages in thread From: David C. Hoos, Sr. @ 1997-06-12 0:00 UTC (permalink / raw) 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 > > > ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~1997-06-13 0:00 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox