# Killing a function on certain condition?

**URL:** <https://forum.kirupa.com/t/killing-a-function-on-certain-condition/194727>\
**Category:** flash\
**Created:** [July 25, 2006, 8:40pm UTC](https://forum.kirupa.com/t/killing-a-function-on-certain-condition/194727 "2006-07-25T20:40:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![REEF](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@REEF](https://forum.kirupa.com/u/REEF)\
**Post date:** [July 25, 2006, 8:40pm UTC](https://forum.kirupa.com/t/killing-a-function-on-certain-condition/194727/1 "2006-07-25T20:40:53Z")

</div>

Ive always wondered how to do this because functions rock but they cause me so much pain due to how I use them.

For example. Say we’re driving a ship at a constant rate of 45 miles per second:

```auto
function milesTraveled() {
	myMiles += 45;
	if (myMiles>=4500) {
		myMiles = 4500;
		trace("reached destination");
		refillGas();
	}
}
setInterval(milesTraveled, 1000);

```

Now as you can see it runs the function refilllGas(); but it -keeps- on running refillGas(); due to the setInterval that runs the main function everysecond.

Any way to cut the function milesTraveled for good once I hit a certain condition?
