-
-
Save avysk/902711f3e597e89da503ac6b3ab82fcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <setjmp.h> | |
static jmp_buf buf1, buf2; | |
#define FOR(VAR, START, FINISH) if (!setjmp(buf1)) { for (int (VAR) = START; (VAR) <= (FINISH); (VAR)++) { | |
#define NEXT if (!setjmp(buf2)) continue | |
#define ENDFOR longjmp(buf1, 1); } longjmp(buf2, 1); } | |
int go(int finish) { | |
printf("Finish: %d\n", finish); | |
FOR(i, 1, finish) | |
if (i % 2) { | |
NEXT; | |
puts("odd exit"); | |
} else { | |
NEXT; | |
puts("even exit"); | |
} | |
ENDFOR | |
} | |
int main() { | |
go(7); | |
go(8); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment