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

*To*: mathgroup at smc.vnet.net*Subject*: [mg60781] Re: N-nested For loops, with N variable - Best way to implement?*From*: Bill Rowe <readnewsciv at earthlink.net>*Date*: Wed, 28 Sep 2005 01:41:33 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

On 9/27/05 at 3:45 AM, lost.and.lonely.physicist at gmail.com wrote: >I'd like to seek some advice regarding how to best implement N >nested For loops such that The best choice in Mathematica is almost certainly not to do this. There is almost always a significant performance penalty for using For loops. >(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? Possibly. But you need to provide some detail as to what you want to do. Quite possibly there is no need to use an explicit index at all. For example if data is a vector of items you want summed, Plus@@data runs much faster than a For loop or using Table. Note for this purpose Tr[data] or Total[data] will be faster than Plus@@data. -- To reply via email subtract one hundred and four