How do you write this down?

Started by
20 comments, last by Sik_the_hedgehog 8 years, 9 months ago

In the unlikely situtation doA() and doB() don't use or change x,y,z there's always:


for(i = 0; i < x; i++)
{
    if(v > 0 && doA())
    {
        doB()
    }
    else if(v <= 0 && doB())
    {
        doA()
    }
}

z += ((x^2 + x)/2) + y*x + x
y += x + (x^2 + x)/2
x = 0
Advertisement

I think the idea is that you take the comparison out of the loop for performance reasons, though.

...actually that's a good question: assuming the loop is short enough, would the compiler optimize out the comparison within the loop as two separate loops altogether? This would solve the clarity issue completely (simply write it once and let the compiler sort it out as needed).

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

This topic is closed to new replies.

Advertisement