On Friday, 15 February 2013 at 09:02:06 UTC, Diego wrote:
You can use static variables inside that function:
void
TimerCallback(int number) {
statement_1;
static bool i_found_my_magic_number = false;
if(!i_found_my_magic_number && number == MY_MAGIC_NUMBER) {
i_found_my_magic_number = true;
// Do what you need.
}
statement_3;
}
Static variables does not lose its value over different
function calls, so you can use it to control what happen inside
functions over calls without using global variables.
Hope that helps.
Dear Diego,
Thanks for caring to reply.
In fact, it is not a business requirement or something like that.
My question is purely on academic interest.
The if_condition being costly is not exaclty what I want to
escape from. I am thinking why I am forced to execute the
condition, when I know that I will not be benefited.
Thanks,
Gopan.