Re: N-nested For loops, with N variable - Best way to implement?
- To: mathgroup at smc.vnet.net
- Subject: [mg60787] Re: N-nested For loops, with N variable - Best way to implement?
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Thu, 29 Sep 2005 05:40:55 -0400 (EDT)
- References: <dhau6j$irs$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
lost.and.lonely.physic... at gmail.com wrote: > Hello everyone > > I'd like to seek some advice regarding how to best implement N nested > For loops such that > > (1) N is a variable - i.e. I tell Mathematica what N is and it does the > For loop N times. > > (2) For each loop I want to do something like For[a_k=1,a_k<=A,a++, > ...], k = 1,...,N and I want to use the all the running values > {a_1,...,a_N} to do stuff within the innermost loop. > > Maybe there's even a way to do this w/o using For loops? Table maybe? > > Thanks for the advice. If A^n is not too big and you're using version 5.1 or later then Scan[ Function[a, (* operate on a[[1]],...,a[[n]] here *) ], Tuples[ Range@A, n] ] will do what you want.