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 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-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)?

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