Last Updated: February 25, 2016
·
703
· bogdancernat

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;
}

4 Responses
Add your response

Seriously? then you can also use this. In my opinion one more nice-looking.

#define InfiniteLoop for(;;)
InfiniteLoop {

}
over 1 year ago ·

@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.

over 1 year ago ·

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.

over 1 year ago ·

@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.

over 1 year ago ·