Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13261 > unrolled thread

Re: goto label, no loop, Mathematica 6

Started by"djmpark" <djmpark@comcast.net>
First post2013-01-24 06:17 +0000
Last post2013-01-24 06:17 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: goto label, no loop, Mathematica 6 "djmpark" <djmpark@comcast.net> - 2013-01-24 06:17 +0000

#13261 — Re: goto label, no loop, Mathematica 6

From"djmpark" <djmpark@comcast.net>
Date2013-01-24 06:17 +0000
SubjectRe: goto label, no loop, Mathematica 6
Message-ID<kdqjlb$3cs$1@smc.vnet.net>
Your code example seems quite confused and not very specific as to what
constitutes the model.

First, you can't use Switch as a variable since it is a Mathematica
function, which you might actually use.

I'm not quite certain about the use of Goto but I don't think you could use
it to transfer between notebook cells.  You have to use it within a single
cell, or within a compound statement, or within a Module as is shown on the
Help page for Goto.

Goto may have a few uses but is not generally a good programming method. You
could try something like this:

evaluateModel[modelType_] :=
  (If[modelType == 2, Goto[model2]];
   Print["Evaluating Model 1"];
   Goto[end];
   Label[model2];
   Print["Evaluating Model 2"];
   Label[end]; "Return the model"); 

But a far better method would be:

evaluateModel[modelType_] :=
 Switch[modelType,
  1, Print["Evaluating Model 1"]; "Return the model",
  2, Print["Evaluating Model 2"]; "Return the model"] 


David Park
djmpark@comcast.net 
http://home.comcast.net/~djmpark/index.html 




From: bob [mailto:stefanie.schubert@whu.edu] 


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

Thanks for any help!! 

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web