home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16943 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  1.3 KB

  1. Path: sparky!uunet!spool.mu.edu!umn.edu!cybrspc!roy
  2. From: roy%cybrspc@cs.umn.edu (Roy M. Silvernail)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: The Correct Way To Write C if-Statements
  5. Message-ID: <c6ZkuB5w165w@cybrspc.UUCP>
  6. Date: Sat, 21 Nov 92 02:59:11 CST
  7. References: <1992Nov20.093957@gese.ge14.mdadv.gv.at>
  8. Organization: Villa CyberSpace, Minneapolis, MN
  9. Lines: 48
  10.  
  11. sca@gese.ge14.mdadv.gv.at (Petzi Schweda) writes:
  12.  
  13. > think you'll end up a little bit messy when using this one inside blocks:
  14. > for (...)
  15. >     {
  16. >     if  (cond)
  17. >     {
  18. >         state;
  19. >     }
  20. >     else
  21. >     {
  22. >         state2;
  23. >     }
  24. >     }
  25. > too much paranthesis in this column, for my taste ...
  26.  
  27. Yuk!  OK, the original article notwithstanding, what's wrong with this?
  28.  
  29. for (...) {
  30.     if (cond) {
  31.         state;
  32.     } else {
  33.         state2;
  34.     }
  35. }
  36.  
  37. I've also been known to do this...
  38.  
  39. for (...) {
  40.     if (cond) {
  41.         state;
  42.     } else
  43.     if (other_cond) {
  44.         state2;
  45.     } else
  46.     if (yet_another_cond) {
  47.         state3;
  48.     }
  49. }
  50.  
  51. This makes it easy to add (yet_one_more_last_minute_condition) without
  52. having to decode brace placement.
  53. --
  54. Roy M. Silvernail --    [my machine ] "Sometimes, you're the windshield....
  55. roy%cybrspc@cs.umn.edu  [my opinions]            sometimes, you're the bug!"
  56. cybrspc!roy@cs.umn.edu  [my $0.0275 ]                      --Mark Knopfler
  57.