Article View: comp.std.c
Article #3988Re: Situation indicators (long) (was: How to eliminate GOTO?)
From: Mike Lee
Date: Wed, 13 Sep 1995 20:21
Date: Wed, 13 Sep 1995 20:21
35 lines
1835 bytes
1835 bytes
Back when I was a wee little laddy and stumbled across my first "while"
statement, I initially misinterpreted the definition. When I finally
understood how it worked I was rather disappointed. I took the "while"
to mean that statements in the block should be executed until the
condition is no longer true, and then should stop immediately, _even in
the middle of the block_.
For example:
drive(car, BEACH);
while (weather() == SUNNY)
{
play_in(water);
dry_off();
apply(sunscreen);
sleep(1200);
}
drive(car, HOME);
So, if the weather turned foul, we would drive home without further ado
and not be troubled to apply sun screen and take a nap first.
Now, obviously this is not an efficient construct. Each time a side
effect could cause the controlling expression to change, the test must be
repeated. The more complex the expression or the more stuff modified
inside the block, the more overhead is involved. There is also the
matter of whether called functions should respect the controlling
expression...perhaps when you are in the middle of applying sunscreen,
it gets too dark to see and you can't finish the job :)
But, efficiency aside, I like this construct because it resembles
conventional English usage of the term "while" and because it leads
to thinking in terms of loop invariants.
mikey
Technical Details
Message-ID:
<437egh$r6g@news.cerf.net>Path:
arc1-ca.pugleaf.net!news.cerf.net!banzai!mikeyReferences:
<4321kd$cne@news0.rain.rg.net> <I.predict.jos.will.like.this.article>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.cerf.net!banzai!mikey From: mikey@banzai.ontek.com (Mike Lee) Newsgroups: comp.std.c Subject: Re: Situation indicators (long) (was: How to eliminate GOTO?) Date: 13 Sep 1995 20:21:37 GMT Organization: Ontek Corporation -- Laguna Hills, California Message-ID: <437egh$r6g@news.cerf.net> References: <4321kd$cne@news0.rain.rg.net> <I.predict.jos.will.like.this.article> NNTP-Posting-Host: banzai.ontek.com