MathGroup Archive 2004

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

Search the Archive

Re: If-statement problems

  • To: mathgroup at
  • Subject: [mg49523] Re: If-statement problems
  • From: Bill Rowe <readnewsciv at>
  • Date: Thu, 22 Jul 2004 02:46:49 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

On 7/21/04 at 6:39 AM, aaronfude at (Aaron Fude) wrote:

>New to Mathematica. I can't figure out how to use the if-statement
>for pure flow control.

>Here's an example:

>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]]];

>I want to assign to a b c and d the 4 values from A. Obviously,
>that's not what happens. How do I accomplish what I need?

This is almost correct. Change if to If and it would work as you expect. All built in functions in Mathematica begin with an upper case character.

But for the task os assigning elements of a list to variables, this is got to be about the most inefficient way to do it in Mathematica. For a short list like you have heere, probably the simplest and most efficient way to do what you want would be

To reply via email subtract one hundred and four

  • Prev by Date: Re: simple problem with Map?!?
  • Next by Date: Re: simple problem with Map?!?
  • Previous by thread: Re: If-statement problems
  • Next by thread: RE: If-statement problems