View Full Version : (simple question) how to make an if statement run only once?

09-08-2006, 10:58 PM
in order to run an if statement only once, I'm using a counter as a conditional and setting the counter to equal one once the if statement runs.

Is there another way to run an if statement only once?

09-09-2006, 12:38 AM
This should be in the Javascript section...

You really need to give a better explanation; how are you currently running whatever it is? You could place it within a function?

09-09-2006, 01:00 AM
its a simple if(x>5){

The thing is that I just want it to run only once and when x becomes greater than 5.

The reason why I don't use x==5 is because x may jump from 4 to 6, but I only need it to run once past the threshold of 5.

I also can't use a range because perhaps x will take on a value in that range more than once.

The simple way i do it is


if($m==0 && $x>5){

So, it runs only once. But, can you do it without the counter?

09-09-2006, 01:35 AM
You need some kind of flag to tell the if statement to run or not. The counter is probably the best way to do it. Why don't you want to use the counter? There is really no way to it without a counter. You will have to get the statement to become false.

09-09-2006, 02:27 AM
I'll need to use this function a lot. Adding a counter causes the system to keep track of another variable which might slow processing down.