# How do I get my if statement to execute once, when its condition is met?

**URL:** <https://forum.kirupa.com/t/how-do-i-get-my-if-statement-to-execute-once-when-its-condition-is-met/188832>\
**Category:** Uncategorized\
**Created:** [May 11, 2006, 5:22am UTC](https://forum.kirupa.com/t/how-do-i-get-my-if-statement-to-execute-once-when-its-condition-is-met/188832 "2006-05-11T05:22:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![messlah](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@messlah](https://forum.kirupa.com/u/messlah)\
**Post date:** [May 11, 2006, 5:22am UTC](https://forum.kirupa.com/t/how-do-i-get-my-if-statement-to-execute-once-when-its-condition-is-met/188832/1 "2006-05-11T05:22:02Z")

</div>

Hey all,

Im trying to create a little menu here. It has 8 options (with rollon animation, selected, rolloff animation), so I thought I would have a variable for each menu option.

So when menu option 1 is selected my variable (navvar) will = 1.

Here is my if statement / loop.

//for option1  
if(\_root.navvar == “1”){  
\_root.nav\_main.home.gotoAndPlay(“onanimation”);  
}

//options 2-8 like above else if(\_root.navvar == “2”){ etc

Now my problem is that when the above is looping over its 2 frames, obvisouly it only plays a few frames of my “onanimation”, which means I get a flickering effect.

Could someone show me how I can setup this code so that when navvar = 1 I can simply go and play my “onanimation” once only, (until another variable is selected etc)

Any help is much appreciated.
