what, exactly, is this line supposed to be doing? I realize I’m getting ready to fall asleep and shouldn’t be looking at code but I swear it’s comparing x to zero, and I think you want to be setting intX to zero. (intX instead of x and = instead of ==). [or am I coding the wrong language in my head again?]
I don’t think it’s getting ignored. I just don’t see it doing anything.
I’m not sure where you’re going with this code, but again, I need to go to sleep. If you’re trying to toggle through eight settings, the code is going to fly through all those settings rapidly until you stop pressing the button, kind of like a roulette wheel. If you want a one button toggle, the code needs a process where it waits for you to stop pressing the button before allowing itself to increment the next time the button is pushed.
int intX = 0
while (0 == 0)
intButtonPressed = GetRxInput(5);
if (ButtonPressed > 192)
if (intX > 7)
intX = 0; // reset it back to zero <--THIS WAS THE BAD LINE
// PrintToScreen ("%d\n",intX); // Should not need to cast it, it's aready an int
You should avoid using variable names like a,b,c,x,y,z because they have no meaning and make it very difficult to read the code. While it’s not a big deal on a small program like this it would be very hard on a program with 50+ variables and 300+ lines of code.
Much like the debate around writing comments, that’s a matter of opinion. For the above code, “intX” or even “x” is a perfectly readable name because the only purpose the variable serves is to be a counter.
Trying to name a variable simply because there’s a belief that says “named variables make reading code easier” can get you into just as much trouble as leaving them alone, but more importantly, it can cause the programmer to waste a lot of time performing a task that either doesn’t add value or doesn’t add as much value as some other task they could be doing.
The time to change “x” to a more meaningful name is when x has become important enough to need a more meaningful name. Until then, “x” works just fine. I’ve seen it work perfectly well in programs 300+ pages long, not just 300+ lines long.