|
Moo Apprentice
Joined: 10 Apr 2009 Posts: 145
|
Posted: Fri Jul 09, 2010 9:08 pm
Nested #forall? |
#forall uses %i as the variable that changes for each item...
But what happens if you put one #forall inside another?
I was expecting/hoping that %i would be the item selected from the "inner" forall, and the loops would work like nested for or foreach in other languages..
So..
Code: |
$a=a|b|c
$b=1|2|3
#forall $a {
#echo A:%i
#forall $b {
#echo B:%i
}
} |
Would hopefully produce:
Quote: |
A:a
B:1
B:2
B:3
A:b
B:1
B:2
B:3
A:c
B:1
B:2
B:3 |
But instead it produces:
Quote: |
A:a
A:b
A:c
A:a
B:a
B:a
B:a
A:b
B:b
B:b
B:b
A:c
B:c
B:c
B:c |
Which seems a bit strange, and not helpful.. |
|
|
|
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Fri Jul 09, 2010 9:14 pm |
Inner loop is %j, then %k, then %l ... IIRC that's how it went.
So you should have something like this.
Code: |
$a=a|b|c
$b=1|2|3
#forall $a {
#echo A:%i
#forall $b {
#echo B:%j
}
}
|
|
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
|
Moo Apprentice
Joined: 10 Apr 2009 Posts: 145
|
Posted: Fri Jul 09, 2010 9:20 pm |
Progonoi wrote: |
Inner loop is %j, then %k, then %l ... IIRC that's how it went. |
It works!
Now, why don't the docs mention that? |
|
|
|
GeneralStonewall Magician
Joined: 02 Feb 2004 Posts: 364 Location: USA
|
Posted: Fri Jul 09, 2010 10:35 pm |
More accurately, the outermost loop is %i and each nested loop within it progresses by one alphabetic letter.
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Sat Jul 10, 2010 12:10 am |
You are correct that the documentation does not mention this (even though it has existed since Zmud). I have made a comment on the appropriate documentation page about this.
|
|
|
|
|
|