PDA

View Full Version : aligning arrays in loops


indestructibleman
02-14-2008, 05:35 PM
is there a way to execute a loop with multiple arrays so that $f[0] will correspond with $s[0] and $f[1] will correspond to $s[1], etc . . . ?

for example

int $first[] = {0,1,2,3,4};

int $second[] = {0,1,2,3,4};

for ($f in $first)

for ($s in $second )

{
print $f;
print ($s + "\n");
}


this returns
00
01
02
03
04
10
11
12
13
14
etc . . .


could it be made to return only


00
11
22
33
44
?

thanks,
will

Diamant
02-14-2008, 06:09 PM
do a standard loop..

int $first[] = {0, 1, 2, 3, 4};
int $second[] = {0, 1, 2, 3, 4};

int $i = 0;
for ($i: $i < size($first); ++$i)
{
print ($first[$i] + $second[$i] + "\n");
}


-Rich

indestructibleman
02-14-2008, 06:34 PM
oh, duh. that makes sense. thanks!

CGTalk Moderation
02-14-2008, 06:34 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.