home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!infonode!ingr!b30news!mueller
- From: mueller@b30news.b30.ingr.com ( Phil Mueller )
- Subject: Re: a question about if and case
- Message-ID: <1992Dec14.175249.15909@b30.ingr.com>
- Sender: mueller@b30.ingr.com (Phil Mueller)
- Organization: Intergraph
- References: <1gi6poINN3lv@nz12.rz.uni-karlsruhe.de> <1992Dec14.165638.9597@b30.ingr.com>
- Date: Mon, 14 Dec 1992 17:52:49 GMT
- Lines: 74
-
- In article <1992Dec14.165638.9597@b30.ingr.com> mueller@b30news.b30.ingr.com ( Phil Mueller ) writes:
- >In article <1gi6poINN3lv@nz12.rz.uni-karlsruhe.de> "hans friedrich steffani" <GM08@DKAUNI2.BITNET> writes:
- >>
- >>i have something like
- >>
- >>int i;
- >>
- >>if( i == 1 || i == 25 || i == 125 )
- >> {
- >> /* do something sophisticated */
- >> }
- >>if( i == 2 || i == 30 || i == 244 )
- >> {
- >> /* do something different */
- >> }
- >>
- >>or should i use
- >>
- >>switch( i )
- >> {
- >> case 1:
- >> case 25:
- >> case 125:
- >> /* do something sophisticated */
- >> break;
- >>
- >> case 2:
- >> case 30
- >> case 244:
- >> /* do something different */
- >> break;
- >>
- >> default:
- >> break
- >> }
- >>
- >
- >I would do this
- >
- > switch( ii ) {
- > case 1:
- > case 25:
- > case 125:
- > /* something */
- > break; /* 1,25,125 */
- >
- >
- > case 2:
- > case 30:
- > case 244:
- > /* something */
- > break; /* 2,30,244 */
- >
- > default:
- > error( "%s, ii has value %d, should be on of %s, in %s:%d",
- > "internal error", ii, "{1,2,25,30,125,244}", __FILE__, __LINE__ );
- > break;
- > } /* switch ii */
- >
- >
- >1) I can just scan down the line to see the values.
- >2) defensive error message gives me all the info I have so I can fix.
- >
- >( I split up the error line to fit on one line. You should get the idea. )
- >
- >I hard-coded in the valid values. Does anyone know a way to make that
- >automatic?
-
- Ooooh, sorry about that, bad post.
-
- I should have asked, "Why are these values hard-coded?"
- --
- Phil Mueller mueller@b30news.b30.ingr.com
- The preceeding opinions are not necessarily those of Intergraph Corporation.
-