C style
preece at ccvaxa.UUCP
preece at ccvaxa.UUCP
Wed Oct 30 01:35:00 AEST 1985
> Your examples are not equivelent, you forgot the "else result[i]=0;"
> clause for every if on the nested example. /* Written 6:52 pm Oct
> 26, 1985 by BLARSON%ECLD at usc-ecl.ARPA in ccvaxa:net.lang.c */
----------
No, there aren't supposed to be else clauses -- the "result[i]=0"
is supposed to happen ONLY if all tests but the last are passed.
That is, the function1 - function5 tests are checking whether it
is valid to apply the actual test and the failure of any of them
is supposed to suppress assignment and terminate the loop.
The suggestion that the tests could be written as a single
expression by joining them with ANDs is fine for the simplified
example, but not applicable if there were additional code involved
in setting up before each test
Several other comments were received. A couple of people suggested
using an array of functions and looping over that array. That also
wouldn't work if there were additional code preceding each call,
but is reasonable for the simplified example. Care would be required
in making it clear what was being done and how to find out which
functions were being called in what order, but this approach has a
nice generality (the list of functions could be built from a
description, automatically).
Prof. Lo also wrote to clarify the posting about LOOP-EXIT-END to
which I originally responded. The intent was to not use a for
loop where it is possible to exit without completing the iteration.
That's reasonable, though I think it can be argued that the use of
the "for" construct makes it clearer that the NORMAL behavior is
intended to be a loop over those hundred values and the annotation
should make clear under what circumstances an ABNORMAL exit is
made before the end. It is important to readability that the
language used make clear not only WHAT happens but also WHY.
--
scott preece
gould/csd - urbana
ihnp4!uiucdcs!ccvaxa!preece
More information about the Comp.lang.c
mailing list