From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Please help Date: Tue, 27 Jan 1998 18:18:21 -0500 Organization: Two pounds of chaos and a pinch of salt. Lines: 56 Message-ID: <34CE6B3D.36E7@cs.com> References: <01bd2b45$72498300$3494efc2 AT hans> NNTP-Posting-Host: ppp242.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hans Winther wrote: > > I have seen the use of case and switch > commands in some demo programs, > but i don't know what they mean. > I know just about all other basic > commands in C/C++. This may sound kind of obvious, but have you tried reading about them? Every C language text in existence mentions switch/case blocks. If you're familiar with Pascal, the syntax is very similar to CASE..OF blocks. 'switch/case' is a conditional construct that allows you to branch to a specific block of code depending on the value of an integral expression. When executed, the switch statement looks through all case labels for one corresponding to the value of the test expression. If it finds one, it begins execution of the succeeding line of code. Execution "falls through"; i.e., it does not stop when it reaches another case label; the 'break' statement may be used in this case. If no match is found, the 'default' label may be used to specify additional code to run. Example: int choice; printf( "Please pick an item from 1 to 3: " ); scanf( "%d", &choice ); switch( choice ) { case 1: printf( "You picked choice #1.\n" ); break; case 2: printf( "You picked choice #2.\n" ); break; case 3: printf( "You picked choice #3.\n" ); break; default: printf( "That's not a valid choice.\n" ); break; /* optional, but a good habit */ } hth -- --------------------------------------------------------------------- | John M. Aldrich | "To be 'matter of fact' about the | | aka Fighteer I | world is to blunder into fantasy-- | | mailto:fighteer AT cs DOT com | and dull fantasy at that, as the real| | http://www.cs.com/fighteer | world is strange and wonderful." -LL | ---------------------------------------------------------------------