Re: basic issue with do and :=

• To: mathgroup at smc.vnet.net
• Subject: [mg60433] Re: [mg60402] basic issue with do and :=
• From: "benshimo at bgumail.bgu.ac.il" <bsyehuda at gmail.com>
• Date: Fri, 16 Sep 2005 03:49:31 -0400 (EDT)
• References: <200509150916.FAA15855@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```if you check on b with ?b you will get

On 9/15/05, David <isolanoster at gmail.com> 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}]
> ---------------------------
>
> [note ":=" instead of "=" on the second line].
>
> namely the output is: "b[2]:=a[i]+1" for all i
>
>
>
> Is there any compact way to define: "b[i] :=a[i]+1" for all i ?

b[1] := a[i] + 1

b[2] := a[i] + 1
etc ,
this means that in the definition the left hand side is evaluated
immediately while the right hand side is delayed until a call for that
definition. Mathematica did here exactly what should be expected from it.
I wonder whay do you need to define a FUNCTION for each value of i?
b[i_]:=a[i]+1 will do. you do not need to enter this inside a loop.
yehuda