How do I Stop a Function ?

How so I stop a function from running?
I have a script that calls a custom function when the player enters a trigger but I can’t get it to stop when the player leaves the trigger?

#pragma strict

var boulder01 : GameObject;
var BoulderSpawn01 : Transform;

function OnTriggerEnter ()
{
	SpawnBoulder(); //Call new function
}

function SpawnBoulder ()
{
	for (var x = 1; x < 2; x++) //Set max limit of spawns
	
		{
			yield WaitForSeconds (5);
			Instantiate(boulder01, BoulderSpawn01.transform.position, BoulderSpawn01.transform.rotation);
		}
}

Any suggestions?

I write in c# so this may need some work.

var boolTrueFalse = false;

 function OnTriggerEnter()
    {
       boolTruFalse = true;
       //Call anything you want here. 
    }

 function OnTriggerExit()
    {
       boolTruFalse = false;
       //Call anything you want here. 
    }



 Update()
 {
    if(boolTrueFalse)
    {
     spawnBoulder();
    }
 }

Coroutines will help you out. StartCoroutine in OnTriggerEnter, and StopCoroutine in OnTriggerExit.