If statements are all you need

Started by
12 comments, last by Nypyren 8 years ago

Eh, I was expecting something much worse. The lack of arrays (or whatever) seems to be the real problem here (and really, most of the ifs come from doing the same thing on multiple variables).

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.
Advertisement

At first I thought it would just be if statements instead of other control flow techniques. But no, it's much worse than that.


if (printHPMax - 90 >= 0)
{
    hpTen = 9;
}
else if (printHPMax - 80 >= 0)
{
    hpTen = 8;
}
else if (printHPMax - 70 >= 0)
{
    hpTen = 7;
}
else if (printHPMax - 60 >= 0)
{
    hpTen = 6;
}
else if (printHPMax - 50 >= 0)
{
    hpTen = 5;
}
else if (printHPMax - 40 >= 0)
{
    hpTen = 4;
}
else if (printHPMax - 30 >= 0)
{
    hpTen = 3;
}
else if (printHPMax - 20 >= 0)
{
    hpTen = 2;
}
else if (printHPMax - 10 >= 0)
{
    hpTen = 1;
}
else if (printHPMax - 10 < 0)
{
    hpTen = 0;
}

this isn't standard programming practice?!.....well shit...

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

Ifs? Nah, MOV is all you need

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator


this isn't standard programming practice?!.....well shit...

Of course not! It's supposed to look like this:


hpTen = printHPMax - 90 >= 0 ? 9 : printHPMax - 80 >= 0 ? 8 : printHPMax - 70 >= 0 ? 7 : printHPMax - 60 >= 0 ? 6 : printHPMax - 50 >= 0 ? 5 : printHPMax - 40 >= 0 ? 4 : printHPMax - 30 >= 0 ? 3 : printHPMax - 20 >= 0 ? 2 : printHPMax - 10 >= 0 ? 1 : 0

Overuse of if-statements is a code smell.

Ifs? Nah, MOV is all you need



I lost my shit when it got to the INC replacement :D

This topic is closed to new replies.

Advertisement