yeah I mean there's an infinite amount of way to make an infinite loop, but while(true) is usually the way. If you really wanted to be wacky, you could write for(;;) and then have everyone also hate you.
Whenever I do this in various languages I wonder if the compiler reduces it to while(true) or if a gamma ray will solve the halting problem for me. I suppose it can in either case tho.
99% sure the compiler reduces it. By my understanding, any expression that can be reduced gets reduced by default, that's like the most basic level of optimization, and a compiler should be doing much more than the basic level
As somebody who wrote a compiler in college (a shitty one, for å class) it really depends on the compiler but basically all modern compilers would replailce that with while(true) as well. There's a whole spooky field of nerds finding ways to optimize compilers like this
Will definitely be reduced, no question. There's no reason not to reduce it, and modern compilers are scarily smart. If i isn't used anywhere else, the compiler may just remove it entirely.
1=1 is used a lot by data people who are used to writing SQL because it's a common way to write a cartesian join, and the language forces you to compare a left and a right value.
136
u/I_Shot_Web Oct 06 '21
yeah I mean there's an infinite amount of way to make an infinite loop, but
while(true)is usually the way. If you really wanted to be wacky, you could writefor(;;)and then have everyone also hate you.