Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: goto label, no loop, Mathematica 6
Replies: 3   Last Post: Jan 26, 2013 4:58 PM

 Messages: [ Previous | Next ]
 Bill Rowe Posts: 1,647 Registered: 3/14/08
Re: goto label, no loop, Mathematica 6
Posted: Jan 26, 2013 4:58 PM

On 1/22/13 at 11:18 PM, stefanie.schubert@whu.edu (bob) wrote:

>Hi, I'd like to write down my model (several cells) and afterwards
>implement another version of that model. But as I use the same names
>for variables, Mathematica has to "forget" former assignments.

>A solution woul be something like that (which I don't know how to do
>it in Mathematica unfortunately):

>Switch=1 (*a variable that can be set to 1 or 2: tell matehmatica
>to read only Part 1 (or 2)*) if Switch=2 goto label_switch2 Model
>Part 1 (several cells) label_switch2 MOdel Part 2 (several cells)

>But if I'm right, goto is usually used for loops, so that the order
>is label - goto; but not as required here: goto label

You cannot use Switch as a variable name since this is a
built-in function. And it seems to me the built-in function does
what you are describing without use of a goto operation.

That is:

Switch[x,
1, (code segment 1),
2, (code segment 2)]

will run code segment 1 if x is one and code segment 2 if is 2.

The code segments can be any number of function calls
expressions joined with a semicolon that forms a Mathematica
compound expression. Look at the documentation for Switch.

Date Subject Author
1/24/13 Tomas Garza Hernandez
1/25/13 Tomas Garza Hernandez
1/26/13 Bill Rowe