Translate 'while' loop to 'for' loop


i’m create a grid-like structure and am trying to translate my old loop:

while (dayCount <= lastDay) // creates 30 text fields

to a ‘for’ loop where I can increment the position of each duplicated text field by i * a specified width.

the thing is that i can’t figure out how to do that with my while loop. but i can do it with a ‘for’ loop. that’s why i’m trying to change it.

earlier in my code i use this ‘for’ loop to lay out the row above where i want to start…

for(var i:Number = 0; i < numCols; i++){
     _root.createTextField("dayHeadings" + i, i, indColWidth*i, startSecRowYPos, indColWidth, colHeight);
     _root["dayHeadings"+i].border = true;
     _root["dayHeadings"+i].text = dayHeadings*;

anyone have any ideas?

thanks to anyone for helping out. fumeng.

Just initialize a counter outside the while loop and increment it inside. It’ll essentially be like a for-loop.

Or since (I’m assuming) dayCount is being incremented inside the loop, just use that value as your i through mathematical manipulation.

i didn’t even think of that because i’m so used to using counter variables like i and j in loops. now i’m using:

for (var dayCount:Number=1; dayCount <= lastDay; dayCount++){

thanks for your help.