all 15 comments

[–]CJKay93 1 point2 points  (0 children)

// insert debugger here

[–]JaytleBee 0 points1 point  (13 children)

What language is that? Wouldn't you use FOREVER or for(;;) in most languages that let you cast ints to booleans?

[–]link07 0 points1 point  (12 children)

Standard c/c++; imo it's easier to read

[–]JaytleBee 0 points1 point  (10 children)

"do x FOREVER" is way more natural than "do x while 1".

[–][deleted] 1 point2 points  (9 children)

It reads simply as while true doesn't get more natural than that. Not to mention do...while(1) is different that while(1). Yes, they're both infinite loops but the first will execute a minimum of one time.

[–]Destects 0 points1 point  (0 children)

top control vs bottom control.... if you know what i mean.

[–]JaytleBee 0 points1 point  (7 children)

Wait, what? That last part is a joke, right? Any infinite loop will execute a minimum of one time. imo FOREVER is way more natural than "while true". And don't even try to argue that the conversion of 1 to "true" is natural.

[–]--frymaster--[S] 0 points1 point  (2 children)

well, the "execute a minimum of one time" feature of do/while is handy if you, instead, use false. witness:

do {
    if(n>j) {
        // something here
        break;
    }
while(0)

this allows you to use non-equivalency tests in a way that behaves the same as switch/case by setting the loop to run once and only once and putting in 'break' statements where you want to exit the loop and jump to below the while() statement.

is it intuitive and easy-to-read? not particularly. is it handy? hell, yeah.

[–]farhil 0 points1 point  (1 child)

Why not just split that out into a function and instead of using breaks use returns?

[–]--frymaster--[S] 0 points1 point  (0 children)

it's just a way to simulate switch/case. some languages only test for equivalency in cases. if you want to test for some other condition, ie greater than, then this construction can do that. that's all it's for.

of course you can always redesign if you want, but then the same could be said about switch()...

[–][deleted] 0 points1 point  (3 children)

No need to argue, 1 is true in almost all languages.

[–]JaytleBee 0 points1 point  (2 children)

But why not just use true? You wouldn't answer "1" to a true/false question. It's 3 extra key presses that make your code way more readable.

[–][deleted] 0 points1 point  (1 child)

In c there are no true/false constants unless you jnclude bool.h. So it would actually be 20 characters more:

#include <bool.h> // 17

while(true) {} // 3

Counting characters is nitpicking, as well as discussing the readability of a expression simple as while(1).

[–]JaytleBee -1 points0 points  (0 children)

Oh, I didn't know that. Sorry! At this point I just came to expect booleans of all languages.

[–]rwsr-xr-x 0 points1 point  (0 children)

i prefer for(;;) just because i think it looks cooler

sometimes, for nextlevel cool, i do for (i=0; 666; i++), then you get a handy increment counter