home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!igor!dirac!rmartin
- From: rmartin@dirac.Rational.COM (Bob Martin)
- Newsgroups: comp.lang.c++
- Subject: Re: Tiny proposal for named loops.
- Message-ID: <rmartin.714435942@dirac>
- Date: 21 Aug 92 22:25:42 GMT
- References: <aldavi01.714376080@starbase.spd.louisville.edu>
- Sender: news@Rational.COM
- Lines: 38
-
- 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.
-
-
- |Example:
-
- |for main_loop (...)
- | // ...
- | for inner_loop (...)
- | // ... complex mess of loops ...
- | break main_loop; // somewhere deep inside the loops
- | // ...
- | continue inner_loop; // similarly, deep inside loops
-
-
- |This would eliminate the need for some state variables used with switches,
- |which would make code more readable, and more block-oriented.
-
- |Yes, it's a structured goto. But so are break and continue in the first place
- |-- this is an improvement of them.
-
- IMHO breaks and continues should be avoided, not improved. As you
- say, they are a form of goto. Don't use them, except in case
- statements where you must :-( use break.
-
- State variables are preferable to breaks and continues. Judicious use
- of them allows all loops and blocks to be exited at the same place.
- This benefit outweighs the disadvantage of using a flag.
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-