aligning arrays in loops

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 02 February 2008   #1
aligning arrays in loops

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
 
Old 02 February 2008   #2
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
__________________
Rich Diamant
http://www.rd3d.com
 
Old 02 February 2008   #3
oh, duh. that makes sense. thanks!
 
Old 02 February 2008   #4
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:01 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.