home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12913 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  2.5 KB

  1. Path: sparky!uunet!olivea!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!decvax.dec.com!enigami.mv.com!enigami.mv.com!cory
  2. From: cory@enigami.mv.com (Cory Kempf)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: named loops
  5. Message-ID: <0105011F.c23j5a@dragon.enigami.mv.com>
  6. Date: 26 Aug 92 15:33:10 GMT
  7. Reply-To: cory@enigami.mv.com
  8. Organization: EnigamI, Inc., Nashua, NH
  9. Lines: 58
  10. X-Mailer: uAccess - Macintosh Release: 1.6v1
  11.  
  12.  
  13. In article <BEVAN.92Aug23144650@tiger.cs.man.ac.uk> (comp.lang.c++), bevan@cs.man.ac.uk (Stephen J Bevan) writes:
  14. >In article <1992Aug22.171535.29638@taumet.com> steve@taumet.com (Steve Clamage) writes:
  15. >   The main reason, as I see it, is that it adds no functionality and no
  16. >   notational convenience to the language.  Compare:
  17. >
  18. >       while loop1 (...) { ... break loop1;   ... }
  19. >       while       (...) { ... goto endloop1; ... } endloop1:
  20.  
  21. Howabout:
  22.  
  23.         do { ... } while( ... );
  24.         doLoop: { ... } if(...) goto doLoop;
  25.  
  26.         while ( ... ) { ... }
  27.         whileLoop: if( ... ) { ... goto whileLoop; }
  28.         anotherWhileLoop: if ( ... ) { ... } 
  29.                         else goto endAnotherWhileLoop;
  30.         goto anotherWhileLoop;
  31.         endAnotherWhileLoop:
  32.  
  33. etc.
  34.  
  35. When it comes right down to it, almost EVERY language construct can
  36. be implimented via gotos and if statements.  For that matter, data
  37. structures can be implimented via one dimensional arrays.
  38.  
  39. The reason for NOT doing everything as a if/goto or as an array, is
  40. that the code becomes more self documenting.
  41.  
  42. There are very few rules for what can be done with a goto.  You can
  43. change the point of execution to almost anywhere.
  44.  
  45. With a while loop, there are very strict rules: it is a loop that
  46. will cycle as long as the condition holds true.  
  47.  
  48. These rules are necessary to good programming.  *YOU* may find them
  49. to be a pain, and arbitrary, but when you look at someone else's code,
  50. they can be the only thing that stands between being able to understand
  51. the code and losing your mind.
  52.  
  53. In general, if there is a specific purpose to a goto, rules that define
  54. it's usage (such as exception handling in a pre-3.0 world), it is
  55. best to hide the goto inside of a structure that provides a rigid
  56. set of rules for it use.  It make the code much easier to understand.
  57.  
  58. +C
  59.  
  60.  
  61.  
  62. -------------------------------------------------------------
  63. Cory Kempf                    EnigamI, Inc.
  64. cory@enigami.mv.com           ...!decvax!enigami!cory
  65. Annon:    wi.5036@wizvax.methuen.ma.us
  66.  
  67. "F' cryin' out loud, it's *your* life; shouldn't you at least examine 
  68. your lifestyle values to see if they are really what *you* want."
  69.                                         --Keith Lim
  70.