Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: N-nested For loops, with N variable - Best way to implement?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60767] Re: N-nested For loops, with N variable - Best way to implement?
  • From: dh <dh at metrohm.ch>
  • Date: Wed, 28 Sep 2005 01:41:02 -0400 (EDT)
  • References: <dhau6j$irs$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi lost and lonely,
if you really want to work with loopps and not tensors, you may first 
assemble the iterator and then put it into a table.
E.g. assume we have n loops from 1 to lim. Inside the loop we merely 
print all the running indices:

n=3;
lim=2;
iter=Table[{i[k],lim},{k,n}];
Table[
   Print[Table[i[k],{k,n}]]
   ,Evaluate[Sequence@@iter]]

Because Table has the attribute "HoldAll" you need the "Evaluate". 
Because you want to splice the iterators into the parameter lits for 
Table, you need the "Sequence".

sincerely, Daniel

lost.and.lonely.physicist 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.
> 


  • Prev by Date: Importing (and dealing with) multiple files
  • Next by Date: Re: Checking for a given phrase in an expression
  • Previous by thread: Re: N-nested For loops, with N variable - Best way to implement?
  • Next by thread: Re: N-nested For loops, with N variable - Best way to implement?