Out of curiosity, is there a (language independent*) way to make these two generic statements into one statement?
if (a < b) a += x;
else if (a > b) a -= x;
May also be used as
if (abs(b - a) < x) a = b;
else if (a < b) a += x;
else if (a > b) a -= x;
Oh, now that I'm writing this I'm thinking of something like this:
if (a != b) a += x * (a < b ? 1 : -1);
But that doesn't really benefit the readability. Other ways perhaps?
- = Normal languages, not Brainfuck and the likes or really ancient ones