Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Let us all take a moment

Name: Anonymous 2014-04-15 21:47

to appreciate the underused an undervalued do-while. If I ever had a reason to use a while loop that executed before evaluating the predicate, the do-while loop is the loop I would choose.

Name: Anonymous 2014-04-15 21:55

How do you format your DO-WHILE loops?

do{
appreciate();
}while(moment);

Name: Anonymous 2014-04-15 22:31

>>2

do
{
appreciate();
}
while(moment);

Name: Anonymous 2014-04-15 23:04

>>2
appreciate();
while(moment) appreciate();

Name: Anonymous 2014-04-15 23:11

A simple

int cond = 1;
while (cond) {
if (nigger) {
cond = 0;
}
jews();
}


This code is guaranteed to run at least once, and the nigger condition can be changed whenever you want, be it the first or the 10000th iteration of the loop.

Does do-while have any advantage over a plain old while?

Name: Anonymous 2014-04-15 23:42

appreciate:
...
cmp eax, [moment]
jnz appreciate

Name: Anonymous 2014-04-15 23:51

for(;;;){
if(!moment) break;
appreciate();
}

Name: Anonymous 2014-04-16 0:16

>>4
int moment = 1;

/* ... */

while(moment) {
appreciate();
}

Name: Anonymous 2014-04-16 12:32

GOTO IS THE ONLY USEFUL AND FLEXIBLE THING TO CREATE LOOPS

anus:
code ();

if (cond)
{
code2 ();
goto anus;
}


That would be equal with this invalid C code:

do
code ();
while (cond)
code2 ();

Name: Anonymous 2014-04-16 13:06

>>9
Blithering nonsense.

Name: Anonymous 2014-04-16 13:18

>>10
You will see what's blithering when I hax your anus

Name: Anonymous 2014-04-16 13:49

>>9
looks pretty harmful xDDD

Name: Anonymous 2014-04-16 14:52

>>5
If the compiler is dumb, the test for nigger is executed for each iteration of the loop even though it is only true once.

If the compiler is smart, the programmer still has to read and understand the intent of the test. Anyone who has used a do-while even once knows what the intent is without having to reason about it.

>>6
IIRC on recent x86 common combinations like cmp/jnz evaluate to a single micro-operation. If Cudder were here he'd probably extol the virtues of nevertheless doing loops that way wherever possible, to save on icache.

Name: Anonymous 2014-04-16 16:30

>>13
he test for nigger is executed for each iteration of the loop even though it is only true once.
Do do-while loops really know when to stop without even executing the test for nigger?

the programmer still has to read and understand the intent of the test
How are
if (nigger) {cond = 0};
or
if (nigger) {break};
harder to read than do {} while (nigger)?

Name: Anonymous 2014-04-16 17:13

loops
What's that and why do I need it? Loops are just a primitive special case of tail recursion, which is just a primitive special case of recursion. In a decent language you can write your own loops like this library:
http://hackage.haskell.org/package/monad-loops-0.4.2/docs/Control-Monad-Loops.html

Name: Anonymous 2014-04-16 17:30

My dog's dead !

How does it smell?

Terrible!

Name: Anonymous 2014-04-16 17:36

>>15
Recursion is just a special case of jmp.

Name: Anonymous 2014-04-16 17:53

>>17
jmp is just a special case of UNLEASHING THE SPIRITS OF THE COMPUTER WITH OUR SPELLS!

Name: Anonymous 2014-04-16 20:09

>>18
The NSA and Jewtel are putting spirits in our processors now?!

Name: Anonymous 2014-04-17 4:12

>>5,13,14
Do do-while loops really know when to stop without even executing the test for nigger?

No, but using a do-while loop avoids the need to test the cond flag inside the loop.

It's easier read the do-while form because there's no extra cond, just a control structure which is idiomatic.

HIBT?

>>17
jmp is just a special case of mov eip, eax.

Name: Anonymous 2014-04-17 10:22

>>20
Hey! That's what I was going to say (about jmp).

Name: Anonymous 2014-04-17 13:29

>>20
No, but using a do-while loop avoids the need to test the cond flag
It is going to test the condition every time it reaches the end of the loop. What's the difference?

It's easier read the do-while form because there's no extra cond,
I can't believe you're having a hard time reading a goddamn if.

just a control structure which is idiomatic.
How do you break out of infinite loops? Is break not idiomatic enough for you?

Name: Anonymous 2014-04-17 15:00

>>22
It is going to test the condition every time it reaches the end of the loop. What's the difference?

Compare:

mov byte [cond], 1
while_loop:
cmp byte [cond], 0
je end_while
cmp byte [nigger], 0
je endif
mov byte [cond], 0
endif:
call jews
jmp while_loop
end_while:


versus

do_loop:
call jews
cmp byte [nigger], 0
je do_loop

Name: Anonymous 2014-04-17 23:38

>>23
That was the kind of response I was expecting. Thank you, now I know do-while loops are OMG OPTIMIZED.

Honestly, your arguments about it being more readable didn't make much sense.

Name: Anonymous 2014-04-18 2:17

>>24
A do-while has half as many conditional statements and control variables as a while loop with a control flag. It's objectively less complex.

Name: Anonymous 2014-04-18 3:49

>>24
Actually, most compilers would at least rotate the while version and save a jump, like so:

mov byte [cond], 1
jmp while_start
while_loop:
cmp byte [nigger], 0
je endif
mov byte [cond], 0
endif:
call jews
while_start:
cmp byte [cond], 0
je while_loop

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List