Executing something once within an if statement

It’s a LUA question but it really applies to any video game programming language.

Say I have a file or a piece of code that runs every frame, and say there is an if statement in this code. I want a function/line of code/whatever to run only ONCE within this if statement but everything else to run every frame as long as the if statement is true.

Here’s a hypothetical example in which this code runs every frame:

if(A == B) {

How would I go about doing this? My logic and problem solving skills have failed after running into this problem many times. And is there a way to do this without adding a flustercluck of variables?

Have a flag variable set to false without your function that’s called each frame and add a separate if statement within your code to check against it
local flagcheck = false --Outside of either function

if blah == “llama” then
if not flagcheck then

And at the bottom of your RunOnceFunction() set “flagcheck” (or whatever you name the variable) to true so when the function gets called next frame it won’t be called again.

A few things to make sure of: Make sure the flag variable is within scope of both functions (a local variable to the file will work fine) and if you need the function to ever be called again you must reset the flag to false.

Thanks! I didn’t think of using “if not” statements.

[editline]3rd July 2011[/editline]

Also why does Wizard of Ass think my post is funny? I guess it may be the raw n00bery of the question.