# Is there a way to do this?

• 01-10-2013, 09:46 AM
Leo75
Is there a way to do this?
I got this loop that should loop until it reaches the length of an array
for (var i:int = 0; i < d_listDataArray.length; i++)
The problem is that, it should NEVER be greater than 15.(The array can be all from 1-500)

I guess the pseudo code for this would look like this:
for (var i:int = 0; i < d_listDataArray.length but maximum 15!!; i++) {

Is there any simple way to do this?
It's kind of hard to explain and I don't really know what to google for either..

Kind regards,
Leo.
• 01-10-2013, 11:43 AM
cancerinform
Before the loop you do this:

if (d_listDataArray.length <= 15)
{
var aLength:int = d_listDataArray.length;
}
else
{
aLength = 15;
}
for (var i:int = 0; i < aLength; i++)
• 01-10-2013, 11:55 AM
Leo75
Thanks a lot!
Gonna work on it right away!
Cherio!
Leo.
• 01-10-2013, 07:55 PM
dawsonk
Also
Code:

for (var i:int = 0; i < d_listDataArray.length && i < 15; i++) {
• 01-11-2013, 03:32 PM
jAQUAN
Or

Code:

var i:int;
var max:int = Math.min(d_listDataArray.length, 15);
for(i = 0; i < max; i++){

}

• 01-11-2013, 03:41 PM
Leo75
Thank u all for ur replies!
Got it working!
:-)