int function(void) {
static int i, state = 0;
switch (state) {
case 0: /* start of function */
for (i = 0; i < 10; i++) {
state = 1; /* so we will come back to "case 1" */
return i;
case 1:; /* resume control straight after the return */
}
}
}
Huh, I didn't know you could put case statements arbitrarily anywhere inside a switch block in C. Past the initial WTF, it's a nice hack for implementing coroutines.