home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12751 < prev    next >
Encoding:
Text File  |  1992-08-21  |  2.4 KB  |  57 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uunet.ca!geac!alias!bmcphers
  3. From: bmcphers@alias.com (Brent McPherson)
  4. Subject: Re: Tiny proposal for named loops.
  5. Message-ID: <1992Aug21.203635.2917@alias.com>
  6. Sender: news@alias.com (News Owner)
  7. Organization: Alias Research Inc., Toronto ON Canada
  8. References: <aldavi01.714376080@starbase.spd.louisville.edu> <TSOS.61.714395736@uni-duesseldorf.de>
  9. Date: Fri, 21 Aug 1992 20:36:35 GMT
  10. Lines: 45
  11.  
  12. In article <TSOS.61.714395736@uni-duesseldorf.de> TSOS@uni-duesseldorf.de (Detlef Lannert) writes:
  13. >In article <aldavi01.714376080@starbase.spd.louisville.edu> aldavi01@starbase.spd.louisville.edu (Arlie Davis) writes:
  14. >
  15. >>Since the language is still open to improvements, even those which relate to
  16. >>the more C-oriented personality of C++, I'd like to suggest the addition
  17. >>of named loops.  The syntax would not break any existing code at all.
  18. >>An identifier would be placed just after the "for", "while", "do", or even
  19. >>"if" keyword.  This keyword could be used just after "break" or "continue",
  20. >>to specify exactly which loop to break or continue.
  21. >>
  22. >>Example: [deleted for bandwidth's sake]
  23. >>
  24. >>This would eliminate the need for some state variables used with switches,
  25. >>which would make code more readable, and more block-oriented.
  26. >
  27. >I like your idea. It could certainly make C[++] code safer
  28. >and more legible. There shouldn't be any syntactical problem
  29. >with
  30. >
  31. >     if [<id>] (<expression>) <statement>
  32. >     switch [<id>] (<expression>) <statement>
  33. >     while [<id>] (<expression>) <statement>
  34. >     do <statement> while [<id>] (<expression>) ;
  35. >     for [<id>] (...;...;...) <statement>
  36. >
  37. >A "break <id>;" statement would be useful for the "switch"
  38. >construct as well as for "while", "do...while", and "for",
  39. >as would the "continue <id>;" for the repetitive statements.
  40. >
  41.  
  42. This is a great idea!  I've always used goto's to jump out of
  43. nested loops but this can cause problems.
  44.  
  45. 1) Most people see the word goto and freak out!  Even when it
  46.    is used to jump out of a nested block (which makes up for 
  47.    not having named blocks in C/C++).
  48.  
  49. 2) Most C++ compilers see the word goto and freak out!  Because, 
  50.    the possibility of a backwards jump exists, most C++ compilers I've 
  51.    seen disallow goto to be used in a block with constructors in it.
  52.    Often, it is very hard to satisfy this condition in non-trivial
  53.    cases or where temporary objects are involved. 
  54.  
  55. --
  56. Brent McPherson  (bmcphers@alias.com)
  57.