Skip to content

adds the wonderful and very intuitive `else` clause of `for` and `while` from python back to C

License

Notifications You must be signed in to change notification settings

Oderjunkie/python-else

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

please never use this

Discord Lines of code Minimum C version: 78 (K&R) GitHub

adds the wonderful else clause of for and while from python back to C78

why are you reading this example

#include <stdio.h>

/* include_as = macro: define `PY_FOR(...)` and `PY_WHL(...)` */
/* include_as = syntax_extension: same as macro, but also override `for(...)` and `while(...)` */
#define include_as syntax_extension
#include "pythonelse.h"

int main(void) {
  for (int i = 0; i < 10; i++) {
    printf("i: %d\n", i);
  } else {
    printf("stop. don't use this library. why. WHY.\n");
  }
  
  for (int i = 0; i < 10; i++) {
    printf("i: %d\n", i);
    if (i == 5) break;
  } else {
    printf("pictured: dead code\n");
  }
  return 0;
}