home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uunet.ca!geac!alias!bmcphers
- From: bmcphers@alias.com (Brent McPherson)
- Subject: Re: Tiny proposal for named loops.
- Message-ID: <1992Aug21.203635.2917@alias.com>
- Sender: news@alias.com (News Owner)
- Organization: Alias Research Inc., Toronto ON Canada
- References: <aldavi01.714376080@starbase.spd.louisville.edu> <TSOS.61.714395736@uni-duesseldorf.de>
- Date: Fri, 21 Aug 1992 20:36:35 GMT
- Lines: 45
-
- In article <TSOS.61.714395736@uni-duesseldorf.de> TSOS@uni-duesseldorf.de (Detlef Lannert) writes:
- >In article <aldavi01.714376080@starbase.spd.louisville.edu> aldavi01@starbase.spd.louisville.edu (Arlie Davis) writes:
- >
- >>Since the language is still open to improvements, even those which relate to
- >>the more C-oriented personality of C++, I'd like to suggest the addition
- >>of named loops. The syntax would not break any existing code at all.
- >>An identifier would be placed just after the "for", "while", "do", or even
- >>"if" keyword. This keyword could be used just after "break" or "continue",
- >>to specify exactly which loop to break or continue.
- >>
- >>Example: [deleted for bandwidth's sake]
- >>
- >>This would eliminate the need for some state variables used with switches,
- >>which would make code more readable, and more block-oriented.
- >
- >I like your idea. It could certainly make C[++] code safer
- >and more legible. There shouldn't be any syntactical problem
- >with
- >
- > if [<id>] (<expression>) <statement>
- > switch [<id>] (<expression>) <statement>
- > while [<id>] (<expression>) <statement>
- > do <statement> while [<id>] (<expression>) ;
- > for [<id>] (...;...;...) <statement>
- >
- >A "break <id>;" statement would be useful for the "switch"
- >construct as well as for "while", "do...while", and "for",
- >as would the "continue <id>;" for the repetitive statements.
- >
-
- This is a great idea! I've always used goto's to jump out of
- nested loops but this can cause problems.
-
- 1) Most people see the word goto and freak out! Even when it
- is used to jump out of a nested block (which makes up for
- not having named blocks in C/C++).
-
- 2) Most C++ compilers see the word goto and freak out! Because,
- the possibility of a backwards jump exists, most C++ compilers I've
- seen disallow goto to be used in a block with constructors in it.
- Often, it is very hard to satisfy this condition in non-trivial
- cases or where temporary objects are involved.
-
- --
- Brent McPherson (bmcphers@alias.com)
-