Re: basic issue with do and :=

*To*: mathgroup at smc.vnet.net*Subject*: [mg60409] Re: basic issue with do and :=*From*: albert <awnl at arcor.de>*Date*: Fri, 16 Sep 2005 03:48:50 -0400 (EDT)*Organization*: Arcor*References*: <dgbevg$fol$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

David wrote: > Hi all, > > this works as (I) expected > > ------------------------- > Do[a[i] = i, {i, 10}] > Do[b[i] =a[i]+1, {i, 10}] > ------------------------- > > While this doesn't: > > -------------------------- > Do[a[i] = i, {i, 10}] > Do[b[i] :=a[i]+1, {i, 10}] > --------------------------- this is probably closest to what you expect: Do[With[{ii=i},b[ii]:=a[ii]+1],{i,1,10}]; if you want to understand how this works, you would need to read the chapters about how evaluation works within the helpbrowser. Anyway, probably you will be happier to use (no do-loop requiered!): a[i_] = i b[i_] := a[i]+1 this will work for all i (not only i=1,2,3,4,5,6,7,8,9,10). If you want only integers or only values between 0 and 10 you could also do something like: a[i_Integer] = i b[i_Integer] := a[i]+1 or a[i_Integer/;0<=i<=10] = i b[i_Integer/;0<=i<=10] := a[i]+1 if all this doesn't look obvious to you, you should read the chapters about pattern matching in the online help... good luck, Albert