3 ms·
C also has an empty for loop that works like while (1): for (;;) {}
by oofabz 13y ago
C also has an empty for loop that works like while (1):
for (;;) {}
- jrarredondo 13y agoMy brain always thought that was a no op, but the rule says infinite loop. Why would void be true? Not sure, but there likely was a good reason.
- mtdewcmu 13y agoMaybe because true is defined as anything that's not false?
- gwu78 13y agoThis is also called an "infinite loop"? djb uses this a lot.
- mtdewcmu 13y agoI think the author is seeing things in C's for loop construct that aren't there. C's syntax is conspicuously clean of unnecessary abstraction. The for construct is just three expressions grouped together for the sake of being convenient. It's not a coroutine. The head of the loop can't be a separate context, or part of the loop's scope: it's not inside the curly braces (which aren't part of the loop, anyway; you can use them anywhere -- loops don't have a scope). The first clause is available to initialize variables, but it's perfectly good style to leave it blank and use an already-initialized variable. It doesn't want to be an anonymous function with its own scope and parameters, because then you couldn't do this: int c; for(c=0; str[c] != '\0'; c++) {} printf("Length of string = %d\n", c); C doesn't have a message or a worldview. It's just about saving typing and making common things convenient.