Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active December 25, 2015 08:58
Show Gist options
  • Save rightfold/5126a635281f2559767b to your computer and use it in GitHub Desktop.
Save rightfold/5126a635281f2559767b to your computer and use it in GitHub Desktop.
$ cat foo.c
#include <stdio.h>
void repeat(int n, void (^block)(int)) {
for (int i = 0; i < n; ++i) {
block(i);
}
};
int main() {
int x = 42;
repeat(10, ^(int n) {
printf("%d\n", x + n);
});
return 0;
}
$ clang foo.c && ./a.out
42
43
44
45
46
47
48
49
50
51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment