Skip to content

Instantly share code, notes, and snippets.

@avysk
Created February 25, 2020 15:42
Show Gist options
  • Save avysk/902711f3e597e89da503ac6b3ab82fcc to your computer and use it in GitHub Desktop.
Save avysk/902711f3e597e89da503ac6b3ab82fcc to your computer and use it in GitHub Desktop.
#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