-5

so not too tough I just want to understand if the following is the most efficient/fast way of checking this;

if (misses++)
    run_code();

(Basically if misses increased, run some code, useful for logging missed angles etc.)

P.S will this code run every time misses increases? Thanks :)

EDIT

This does not check if it increased, anybody got any ideas?

2 Answers2

1

try like this:

int b=misses
misses++;
if(misses>b)
{
   run_code();
   b=misses;
}
1

To determine whether a value has increased you have to make a note of the original value, so that you can compare:

void f(int& arg); // might change arg

int main() {
    int misses = 0;
    int old_misses;
    for (int i = 0; i < 10; ++i) {
        old_misses = misses;
        f(misses);
        if (misses != old_misses)
            run_code();
    }
    return 0;
}
Pete Becker
  • 74,985
  • 8
  • 76
  • 165