break, continue, return, goto (net.religion.c)
Mike Shannon
mikes at 3comvax.UUCP
Thu Nov 7 08:52:12 AEST 1985
Craig Miller (in >) and Michael Baldwin (in > >):
In general, I like Craig's suggestions, but offer an improvement(?) over:
> Next:
> > /* using break for ending a complicated search loop */
> > for (m = meeble; m < meeble + NMEEBLE; m++)
> > if (m->glop == forp && m->zip == fweep) {
> > printf("zeegle %2s", m->yorg);
> > m->blazzo += IGUAP;
> > break;
> > }
>
> Becomes:
> for (m = meeble;
> m < meeble + NMEEBLE && (m->glop != forp || m->zip != fweep);
> m++)
> /*
> * walk thru the array till we hit the end or
> * find the right one
> */
> ;
> /*
> * did the find the right one?
> */
> if (m < meeble + NMEEBLE) {
> printf("zeegle %2s", m->yorg);
> m->blazzo += IGUAP;
> }
how about:
p = NULL;
for (m = meeble; m < meeble + NMEEBLE && p == NULL; m++) { /* find it */
if (m->glop == forp && m->zip == fweep) {
p = m;
}
}
if (p) { /* zap it */
printf("zeegle %2s", m->yorg);
p->blazzo += IGUAP;
}
--
Michael Shannon {ihnp4,hplabs}!oliveb!3comvax!mikes
More information about the Comp.lang.c
mailing list