Skip to content

Instantly share code, notes, and snippets.

@m1lkweed
Last active May 24, 2024 06:31
Show Gist options
  • Save m1lkweed/3be672402c43ac5697f1e29bcb79e004 to your computer and use it in GitHub Desktop.
Save m1lkweed/3be672402c43ac5697f1e29bcb79e004 to your computer and use it in GitHub Desktop.
Porting python's `for`/`else` to C with no `setjmp`.
#include <stdio.h>
#define py_for(...) for(int loop_flag = 2, break_called = 0; loop_flag && !break_called; --loop_flag)if((loop_flag == 2) && !break_called)for(__VA_ARGS__, break_called = 0)if((break_called = 1), 0){}else
#define py_whl(...) py_for(;__VA_ARGS__;(void)0)
int main(){
py_for(int i = 0; i < 5; ++i){
printf("%d\n", i);
}else{
puts("egg");
}
}
@m1lkweed
Copy link
Author

Your move, @Oderjunkie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment