Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

The x-Done Loop

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-01-07 7:58

This is a construct that is very useful to avoid either a redundant check or a goto. This...
for(a;b;c) {
 expr1;
 if(d) {
  expr4;
  goto done;
 }
 expr2;
}
 expr3;
done:

...becomes...
for(a;b;c) {
 expr1;
 if(d) {
  expr4;
  break;
 }
 expr2;
} done {
 expr3;
}


where the intent is for statements in a done clause immediately following a loop to be executed if and only if the loop was exited via its termination condition being reached. This also generalises for while() and do-while, here using some common examples.

while(*j) {
 if(*j++ == k) {
  u = v + k;
  break;
 }
} done
 u = v - k;


do {
 if(f(a[i]))
  break;
} while(a[i++]) done {
 g();
}


Discuss.

Name: Anonymous 2013-01-07 9:26

>>13
I wish C had JMP

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List