Enabling loop and disabling loop

Hi!

I have a small project I am working on and I want to know how I can activate a loop and then disable it after a few seconds. If you know, please tell me.

Thanks

I also made some code that works but does not disable the loop.

function HarlemShake () {
	yield WaitForSeconds(15.18);
	harlemEnabled = true;
	while(harlemEnabled == true){
        yield WaitForSeconds(0.1);
        camera.backgroundColor = Color.magenta;
		yield WaitForSeconds(0.1);
		camera.backgroundColor = Color.yellow;
		yield WaitForSeconds(0.1);
		camera.backgroundColor = Color.red;
		yield WaitForSeconds(0.1);
		camera.backgroundColor = Color.green;
		yield WaitForSeconds(0.1);
		camera.backgroundColor = Color.blue;
		yield WaitForSeconds(0.1);
		camera.backgroundColor = Color.white;
	}
	yield WaitForSeconds(14.08);
	harlemEnabled = false;
}

You never go out of the loop, you need to break the loop at some point.

I would probably do something like this,

while( true ){
   camera.backgroundColor = colorArr*;*

i++;
if( i == colorArr.Length ){ i=0; }
yield WaitForSeconds( delay );
time += delay;
if( time >= maxTime ){ break; }
}