MathGroup Archive 2005

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

Search the Archive

Re: goto and label (cont)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57807] Re: [mg57768] goto and label (cont)
  • From: "David Park" <djmp at earthlink.net>
  • Date: Thu, 9 Jun 2005 05:17:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Guy,

Here is an example using Label. Note that if you put in line returns, a ()
pair is necessary to make a compound statement.

(Label[begin];
  f[1] = Random[Integer, {1, 10}]; If[f[1] > 5, Goto[begin]];
  f[2] = Random[Integer, {1, f[1] + 5}];
  If[f[2] <= 5, Goto[begin]];
  {f[1], f[2]})

The following is the same thing done with a While statement.

While[(f[1] = Random[Integer, {1, 10}]; f[1] > 5) ||
   (f[2] = Random[Integer, {1, f[1] + 5}];
    f[2] <= 5), Continue[]]
{f[1], f[2]}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: Guy Israeli [mailto:guyi1 at netvision.net.il]
To: mathgroup at smc.vnet.net


Hi again,

since everyone tells me not to use goto and label (although for the use i'll
describe below it is very comfterable and the simplest way to do it. If
anyone can suggests an alternative/mathematica way of doing it, please do.

the pseudocode with goto

label[l]
do something1
if condition1==true goto[l]
do something2
if condition2==true goto[l]
do some other stuff

as you see i do something1 then check some cond. if something didn't go well
i start doing everything from the start. same for something2. I want to go
all the way to the top. using a while or something alike would need some
variable to hold it and maintaine which is messy. or if a do while loop
exists (?) it will need to do everything and then restart. I want some
mechanism that will restart itself if conditions are not met. goto seems the
only simple option to do it.

again, suggestions are always welcomed

Thanks a lot,

Guy






  • Prev by Date: Re: BinaryIO
  • Next by Date: Keeping the Legendre polynomials in expressions without finding the explicit polinomials
  • Previous by thread: Re: goto and label (cont)
  • Next by thread: Re: goto and label (cont)