Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Moo
Apprentice


Joined: 10 Apr 2009
Posts: 145

PostPosted: 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.. Confused
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: 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
--------------------------------
Reply with quote
Moo
Apprentice


Joined: 10 Apr 2009
Posts: 145

PostPosted: Fri Jul 09, 2010 9:20 pm   
 
Progonoi wrote:
Inner loop is %j, then %k, then %l ... IIRC that's how it went.

Shocked
It works!

Now, why don't the docs mention that? Neutral
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: 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.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: 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.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net