Article View: comp.lang.misc
Article #5287Re: From Modula to Oberon
From: Karl Heuer
Date: Tue, 15 Mar 1988 16:49
Date: Tue, 15 Mar 1988 16:49
20 lines
1200 bytes
1200 bytes
In article <1557@pasteur.Berkeley.Edu> faustus@ic.Berkeley.EDU (Wayne A. Christopher) writes:
>Here's the problem with that construct: I often write [edited --kwzh]
> for (i = 0; i < max; i++)
> if (something) break;
> if (i < max) ...
>If the loop variable is inaccessible outside of the loop there's no way to
>tell how it terminated, except by using an extra flag, which is ugly.
Personally, I think that duplicating the test (i < max) is just as ugly. I
would write the above as
bool issomething() {
for (i = 0; i < max; ++i)
if (something) return (YES);
return (NO);
}
...
if (issomething()) ...
which does fit nicely with the short-scope index variable rule.
Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
Technical Details
Message-ID:
<2973@haddock.ISC.COM>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!necntc!ima!haddock!karlReferences:
<2827@enea.se> <1557@pasteur.Berkeley.Edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!necntc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.misc Subject: Re: From Modula to Oberon Message-ID: <2973@haddock.ISC.COM> Date: 15 Mar 88 16:49:40 GMT References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 19