home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18332 < prev    next >
Encoding:
Text File  |  1992-12-14  |  2.0 KB  |  86 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!infonode!ingr!b30news!mueller
  3. From: mueller@b30news.b30.ingr.com ( Phil Mueller )
  4. Subject: Re: a question about if and case
  5. Message-ID: <1992Dec14.175249.15909@b30.ingr.com>
  6. Sender: mueller@b30.ingr.com (Phil Mueller)
  7. Organization: Intergraph
  8. References: <1gi6poINN3lv@nz12.rz.uni-karlsruhe.de> <1992Dec14.165638.9597@b30.ingr.com>
  9. Date: Mon, 14 Dec 1992 17:52:49 GMT
  10. Lines: 74
  11.  
  12. In article <1992Dec14.165638.9597@b30.ingr.com> mueller@b30news.b30.ingr.com ( Phil Mueller ) writes:
  13. >In article <1gi6poINN3lv@nz12.rz.uni-karlsruhe.de> "hans friedrich steffani" <GM08@DKAUNI2.BITNET> writes:
  14. >>
  15. >>i have something like
  16. >>
  17. >>int i;
  18. >>
  19. >>if( i == 1 || i == 25 || i == 125 )
  20. >> {
  21. >>  /* do something sophisticated */
  22. >> }
  23. >>if( i == 2 || i == 30 || i == 244 )
  24. >> {
  25. >>  /* do something different */
  26. >> }
  27. >>
  28. >>or should i use
  29. >>
  30. >>switch( i )
  31. >> {
  32. >>  case 1:
  33. >>  case 25:
  34. >>  case 125:
  35. >>  /* do something sophisticated */
  36. >>  break;
  37. >>
  38. >>  case 2:
  39. >>  case 30
  40. >>  case 244:
  41. >>  /* do something different */
  42. >>  break;
  43. >>
  44. >>  default:
  45. >>  break
  46. >> }
  47. >>
  48. >
  49. >I would do this
  50. >
  51. >  switch( ii ) {
  52. >    case   1:
  53. >    case  25:
  54. >    case 125:
  55. >      /* something */
  56. >    break; /* 1,25,125 */
  57. >
  58. >
  59. >    case   2:
  60. >    case  30:
  61. >    case 244:
  62. >      /* something */
  63. >    break; /* 2,30,244 */
  64. >
  65. >    default:
  66. >      error( "%s, ii has value %d, should be on of %s, in %s:%d",
  67. >             "internal error", ii, "{1,2,25,30,125,244}", __FILE__, __LINE__ );
  68. >    break;
  69. >  } /* switch ii */
  70. >
  71. >
  72. >1) I can just scan down the line to see the values.
  73. >2) defensive error message gives me all the info I have so I can fix.
  74. >
  75. >( I split up the error line to fit on one line.  You should get the idea. )
  76. >
  77. >I hard-coded in the valid values.  Does anyone know a way to make that 
  78. >automatic?
  79.  
  80. Ooooh, sorry about that, bad post.
  81.  
  82. I should have asked, "Why are these values hard-coded?"
  83. -- 
  84. Phil Mueller    mueller@b30news.b30.ingr.com
  85. The preceeding opinions are not necessarily those of Intergraph Corporation.
  86.