MathGroup Archive 2005

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

Search the Archive

Re: goto and label (cont)

  • To: mathgroup at
  • Subject: [mg57847] Re: goto and label (cont)
  • From: "Carl K. Woll" <carlw at>
  • Date: Fri, 10 Jun 2005 02:29:10 -0400 (EDT)
  • Organization: University of Washington
  • References: <d892ej$sa3$>
  • Sender: owner-wri-mathgroup at

"Bill Rowe" <readnewsciv at> wrote in message 
news:d892ej$sa3$1 at
> On 6/8/05 at 3:21 AM, guyi1 at (Guy Israeli) wrote:
>>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
>>do something1
>>if condition1==true goto[l]
>>do something2
>>if condition2==true goto[l]
>>do some other stuff


> While loops will do what you want. The flow you describe above could be 
> coded as
> While[condition1 == True || condition2 == True,
>   While[condition1 == True, do something1];
>   do something2]
> do some other stuff
> The same functionality as a do while loop can be implemented in 
> Mathematica as a While loop as follows:
> While[True,
>  do something;
>  If[test, Break[]]]

A simpler way to get the functionality of a do while loop is to use the 
single argument form of While:

  do something;

Ray Koopman used this construction in a very nice way to get the 
functionality of Guy's spaghetti code. I quote his construction below:

> The logical OR evaluates its arguments in order, skipping subsequent
> arguments as soon as a True result is found. Use it in a bodyless
> While:
>  While[(something1; condition1) || (something2; condition2)];
>  otherstuff

Carl Woll


  • Prev by Date: Re: Mathematica equivalent complexplot
  • Next by Date: Re: Mathematica equivalent complexplot
  • Previous by thread: Re: goto and label (cont)
  • Next by thread: Re: goto and label (cont)