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

any way to fix this lousy for loop?

Name: Anonymous 2007-07-26 18:16 ID:fISZ2I3i

This doesn't work, but I want to do something like this:


for(int i = 0, bool s = true; ..... ; .....)
{
......;
}


That is,
1) I want to declare two variables
2) I want them to only have scope of the for loop, and
3) I want them to be initialized only once, not every pass through the loop. 

Is there any way to do it besides using awesome goto statements or wrapping the whole loop in braces and declaring i and s there?

Name: Anonymous 2007-07-27 3:59 ID:sFwpRawM

>>1
If lousy loop is:

for (int i = 0, bool s = true; XXX; YYY) {
    ZZZ
}


Then your fix for this lousy loop is:

void lousy_loop(int i = 0, bool s = true) {
    ZZZ
    if (XXX) {
        lousy_loop(YYY); //Might have to change YYY accordingly
    }
}


Then whenever you need it you just call lousy_loop().

P.S.: ONE WORD, SICP

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