Use this the next time you need an infinite loop in C.
I was working on a project that required me to have some infinite loops and I was using
for(;;){
}
but got bored of the way those semi colons look inside the for
loop and realized that I can use the #define
directive of C to create something that looks nice like this
#define ever ;;
int main(){
//some code here
for(ever){
//loop
}
//some code here
return 0;
}
Written by Bogdan Cernat
Related protips
4 Responses
Seriously? then you can also use this. In my opinion one more nice-looking.
#define InfiniteLoop for(;;)
InfiniteLoop {
}
@becreative-germany I posted the tip mostly because when you use the method I described, you get the word "forever" out of the for(ever)
part. Sure there are other ways to achieve an infinite loop, I just like this one better.
Ooooh, nice, and every time I accidentally type two consecutive semicolons I get a compiler error I don't understand, just because someone else was "creative" with syntax sugar.
@fuchsto you get a compiler error because you write syntax that the compiler doesn't accept it. Nobody forces you to write non conventional syntax.