MathGroup Archive 2004

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

Search the Archive

Re: If-statement problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49518] Re: [mg49472] If-statement problems
  • From: DrBob <drbob at bigfoot.com>
  • Date: Thu, 22 Jul 2004 02:46:34 -0400 (EDT)
  • References: <200407211039.GAA07824@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

Here's a partial solution, but you can't use it to set a, for instance, if you've already set a.

ClearAll[assign,a,b,c,d]
assign[symbols_List,data_List,n_Integer?Positive]/;nâ?¤Min[Length/@{
       symbols,data}]&&Head[symbols[[n]]]\[Equal]Symbol:=ToExpression[ToString@\
symbols[[n]]<>"="<>ToString[data[[n]]]]
assign[{a,b,c,d},{5,6,7,8},1]
{a,b,c,d}
assign[{a,b,c,d},{6,7,8,9},1]
{a,b,c,d}

5

{5,b,c,d}

assign[{5,b,c,d},{6,7,8,9},1]

{5,b,c,d}

Here's a solution that doesn't have that limitation, but it requires you to input the symbols as strings.

ClearAll[assign,a,b,c,d]
assign[symbols:{__String},
data_List,n_Integer?Positive]/;nâ?¤Min[Length/@{symbols,data}]:=ToExpression[\
symbols[[n]]<>"="<>ToString[data[[n]]]]
assign[{"a","b","c","d"},{5,6,7,8},1]
{a,b,c,d}
assign[{"a","b","c","d"},{6,7,8,9},1]
{a,b,c,d}

5

{5,b,c,d}

6

{6,b,c,d}

Bobby

On Wed, 21 Jul 2004 06:39:52 -0400 (EDT), Aaron Fude <aaronfude at yahoo.com> wrote:

> A = {5, 6, 7, 8}
> For [n = 1, n <= 4, n++,
>  if [n == 1, a = A[[n]]];
>  if [n == 2, b = A[[n]]];
>  if [n == 3, c = A[[n]]];
>  if [n == 4, d = A[[n]]];
> ]



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: RE: If-statement problems
  • Next by Date: RE: Diophantic Equations with Constraints
  • Previous by thread: Re: If-statement problems
  • Next by thread: Re: If-statement problems