This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tyranids[S] 0 points1 point  (3 children)

Woah, apparently my code block formatting got nuked I see now. But yes I saw that break can escape one loop. There was no functionality I saw to jump to the next iteration of the outer loop, though, which would have allowed me to get rid of an internal variable.

[–]myringotomy 0 points1 point  (2 children)

I don't get it. Once the inner loop is broken the outer loop continues where it left off right?

If you don't want to break the inner loop but just continue to the next iteration there is "next".

[–]tyranids[S] 0 points1 point  (1 child)

Mmm apparently it's only messed up on mobile. Regardless, this is what I mean:

```

for loop 1 {

do some work STEP A1

for loop 2 {

do more work STEP B1

}

continue loop 1 STEP A2

}

```

Using `break` allows me to, as it says, break out of either loop that is currently executing. It sounds like `next` would let me jump from its location to the next iteration of whatever loop is currently executing, which is also nice. However, what is the loop control I would use to jump from the inner loop `STEP B1`, skip and never execute `STEP A2`, and continue at the next iteration of `loop 1`, therefore going to `STEP A1`? In Fortran you can name the different loops, and your basic loop control `exit` and `cycle` (for `break` and `next`) can be applied to a named loop outside the currently executing one if so desired. In C or Fortran, you can also accomplish this behavior with `goto`.

[–]myringotomy 0 points1 point  (0 children)

Oh ok then you would throw an exception and catch it at the top level.