# Help with a For Loop please

**URL:** <https://forum.kirupa.com/t/help-with-a-for-loop-please/311538>\
**Category:** flash\
**Created:** [July 9, 2010, 11:09am UTC](https://forum.kirupa.com/t/help-with-a-for-loop-please/311538 "2010-07-09T11:09:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndyA](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@AndyA](https://forum.kirupa.com/u/AndyA)\
**Post date:** [July 9, 2010, 11:09am UTC](https://forum.kirupa.com/t/help-with-a-for-loop-please/311538/1 "2010-07-09T11:09:16Z")

</div>

Hi everyone,

I am in the process of coding for a navigation menu, and I have a For Loop which, at the moment, duplicates my button movie clip for each of the menu items, and sets some of its properties. Here is the code so far:

```auto
for (i=1;i<6;i++){
	
	duplicateMovieClip("mc", "mc"+i, i);
	
	this["mc"+i].button.text = _root["menu"+i];
	this["mc"+i].hit._width = (this["mc"+i].button.textWidth + _root.textwidthpadding + _root.rightpadding);
	this["mc"+i].button._width = this["mc"+i].hit._width;
	
	_root.totalmenuwidth = (SUM OF ALL EXISTING MC BUTTON WIDTHS) + (_root.menupadding*(i-1)));
	_root.startingpos = (-(_root.totalmenuwidth/2));
	
	this["mc"+i]._x = _root.startingpos + (SUM OF ALL EXISTING BUTTON WIDTHS) + (_root.menupadding*(i-1));
	this["mc"+i]._y = -(one._height/2);

```

My question is: How can I get the sum of the Button widths up to and including that value of i? In other words, how can I derive the sum of:

(when i = 3) mc1.button.\_width + mc2.button.\_width + mc3.button.\_width.  
(when i = 2) mc1.button.\_width + mc2.button.\_width  
(when i = 1) mc1.button.\_width etc.

Thanks in advance for any replies. 🙂  
Andy
