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).
If statements are all you need
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...
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement