Message Boards Message Boards

2
|
9430 Views
|
10 Replies
|
11 Total Likes
View groups...
Share
Share this post:

Can you use two pair of "Goto" and "Label" to exit and re-enter a For loop?

Posted 9 years ago

I could not. Therefore, I went Dynamic and retroactively accomplished the same thing.

POSTED BY: Douglas Youvan
10 Replies

I'm unclear, after reading Wikipedia, how I could have been using Fortran 77 in 1972. But, I think this construction worked in Fortran.

POSTED BY: Douglas Youvan

Sure, it might work. Or not. Here is a link to a Fortran 77 reference

Note in particular: "Restrictions Jumping into the range of a DO WHILE loop from outside its range can produce unpredictable results. "

Also, that manner of coding is spaghetti, independent of the language in which it is programmed.

On a separate note, I suspect much of the Fortran 77 spec was around well before 1977. Having worked with Fortran 66 and also on a compiler for F66, I can say that F77 could not possibly have arrived soon enough.

POSTED BY: Daniel Lichtblau

I would be wary of any code that jumps into a loop. That's just a bad idea in general. (More general: jumping into "scoping constructs" is dangerous since you have to ascertain that the current state is as expected.) Jumping out can be safe if not done carelessly; one often exits loops in similar ways e.g. using Return.

All that said, I will also mention that Mathematica implementation of Goto and a few other jumping constructs (including Return, most especially the zero and one argument flavors but less so the undocumented two argument form) has its vagaries. The code itself is fairly sound but it relies on signals and basically has dynamically (as opposed to statically) scoped behavior. My advice is to use only in well controlled pieces of code. Again, this most likely precludes use for jumping into loops but not jumping out of them.

This may be overly general but it's the best I can say without actual code on which to comment.

POSTED BY: Daniel Lichtblau

On a series note, I don't think this is possible. The Label and the Goto have to be in the same 'compound expression'. And Label must be an explicit element. (Goto doesn't have to be an explicit element) Because of this, you can't. Also the flow control would be very confusing if it re-enters a for-loop and I'm not sure if you want that. Try to avoid them, the readability generally goes down, though exceptions do exist...

POSTED BY: Sander Huisman

enter image description here

POSTED BY: David Reiss

An example of how to construct this Graphic should be included in the documentation for GoTo. Maybe under "Applications" or "NeatExamples".

POSTED BY: Sean Clarke
Graphics[{Black, Circle[], 
  Circle[{0, 1/3}, {1/2, 1}, {Pi + 1/4 Pi, 2 Pi - 1/4 Pi}], 
  AbsolutePointSize[5], Point[{{-1/2, 1/3}, {1/2, 1/3}}]}, 
 PlotRange -> 3/2]
POSTED BY: David Reiss

In an emergency -- if you ever have any desire to use GoTo, please execute the following:

Graphics[{Black, Text[Style["GoTo", 80]], Red, AbsoluteThickness[15], 
  Circle[], Line[{{-Sqrt[1/2], -Sqrt[1/2]}, {Sqrt[1/2], Sqrt[1/2]}}]},
  PlotRange -> 3/2]
POSTED BY: David Reiss

My head just hurts by thinking about it... Follow the letter of Edsger Dijkstra "Go To Statement Considered Harmful"

POSTED BY: Sander Huisman
Posted 9 years ago

lol

I don't want to even begin thinking about this!

kudos for originality

it must be by far the weirdest thing I've ever seen in mma

thanks for sharing

POSTED BY: nik tsak
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract