home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12744 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  1.6 KB

  1. Path: sparky!uunet!igor!dirac!rmartin
  2. From: rmartin@dirac.Rational.COM (Bob Martin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Tiny proposal for named loops.
  5. Message-ID: <rmartin.714435942@dirac>
  6. Date: 21 Aug 92 22:25:42 GMT
  7. References: <aldavi01.714376080@starbase.spd.louisville.edu>
  8. Sender: news@Rational.COM
  9. Lines: 38
  10.  
  11. aldavi01@starbase.spd.louisville.edu (Arlie Davis) writes:
  12.  
  13. |Since the language is still open to improvements, even those which relate to
  14. |the more C-oriented personality of C++, I'd like to suggest the addition
  15. |of named loops.
  16.  
  17.  
  18. |Example:
  19.  
  20. |for main_loop (...)
  21. |  // ...
  22. |  for inner_loop (...)
  23. |    // ... complex mess of loops ...
  24. |          break main_loop;       // somewhere deep inside the loops
  25. |    // ...
  26. |          continue inner_loop;   // similarly, deep inside loops
  27.  
  28.  
  29. |This would eliminate the need for some state variables used with switches,
  30. |which would make code more readable, and more block-oriented.
  31.  
  32. |Yes, it's a structured goto.  But so are break and continue in the first place
  33. |-- this is an improvement of them.
  34.  
  35. IMHO breaks and continues should be avoided, not improved.  As you
  36. say, they are a form of goto.  Don't use them, except in case
  37. statements where you must :-( use break.
  38.  
  39. State variables are preferable to breaks and continues.  Judicious use
  40. of them allows all loops and blocks to be exited at the same place.
  41. This benefit outweighs the disadvantage of using a flag.
  42.  
  43.  
  44. --
  45. Robert Martin                        Training courses offered in:
  46. R. C. M. Consulting                       Object Oriented Analysis
  47. 2080 Cranbrook Rd.                        Object Oriented Design
  48. Green Oaks, Il 60048 (708) 918-1004       C++
  49.