The C 'Goes-To' Operator

Wed Apr 01 2020Make your loops more descriptive with this new operator.

Written by Tilman Roeder

There is a not-very-well-known operator in C for making numeric types 'go to' some target value. It's really useful for writing idiomatic loops like the one below.

#include <stdio.h>

int main(int argc, char const *argv[]) {
    // n `goes to' 0
    int n = 10;
    while (n --> 0) {
        printf("%i\n", n);
    }
    return 0;
}

Go ahead and try compiling this! The output should be:

9
8
7
6
5
4
3
2
1
0