# Simple loop question

**URL:** https://forum.kirupa.com/t/simple-loop-question/117477
**Category:** Uncategorized
**Created:** [July 27, 2004, 7:15pm UTC](https://forum.kirupa.com/t/simple-loop-question/117477 "2004-07-27T19:15:58Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![invisible7](https://avatars.discourse-cdn.com/v4/letter/i/779978/32.png) [@invisible7](https://forum.kirupa.com/u/invisible7)
#### Post date: [July 27, 2004, 7:15pm UTC](https://forum.kirupa.com/t/simple-loop-question/117477/1 "2004-07-27T19:15:58Z")

</div>

I have this color change on an MC. How do I loop this so that when endRGB = true, the color fades back to startRGB and then back to endRGB infinite.

//initiate variables  
onClipEvent (load) {  
// initiate color object  
col = new Color(this);  
//color at start (when movie loads)  
startRGB = new Array(0, 0, 0);  
// edit this to set new color  
endRGB = new Array(143, 0, 0);  
//function to execute color change  
function colorTween () {  
for (i=0; i\<3; i++) {  
difference = endRGB\* - startRGB\*;

//change the value after “difference” to control transform speed  
startRGB\*+=difference\*.005;  
}  
col.setRGB(startRGB[0] \<\< 16 | startRGB[1] \<\< 8 | startRGB[2]);  
}  
}  
//continuously execute the function colourTween();  
onClipEvent (enterFrame) {  
colorTween ();  
}
