#include <stdio.h> int function(void) { static int i, state = 0; switch (state) { case 0: goto LABEL0; case 1: goto LABEL1; } LABEL0: /* start of function */ for (i = 0; i < 10; i++) { state = 1; /* so we will come back to LABEL1 */ return i; LABEL1:; /* resume control straight after the return */ } } int main(){ printf(":%d " , function()); printf(":%d " , function()); printf(":%d " , function()); printf(":%d " , function()); printf(":%d " , function()); return 0; }
想过,但是没想到,还真有啊!