tbednw
Last Updated: February 25, 2016
·
516
· bogdancernat
Aa1a3adc7a22f7024df93ee922843db5

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;
}
Say Thanks
Respond

4 Responses
Add your response

5443
10154941 475885639207813 910458244034183173 n

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

#define InfiniteLoop for(;;)
InfiniteLoop {

}
over 1 year ago ·
5445
Aa1a3adc7a22f7024df93ee922843db5

@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 ·
24571
B67371f1e1c58b42c2b8b11730a2e291

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 ·
24595
Aa1a3adc7a22f7024df93ee922843db5

@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 ·
Awesome Job

E4857be2 008e 11e8 8271 f03109811178
Software Engineer
·
San Francisco Bay Area (San Carlos)
·
Full Time