News for hackers. Stuff that matters.
Re:Loop Exits and Structured Programming: Reopening the Deba... by awinter-py on Monday June 12, 2017 @04:05PM (#14540612)
This is relevant. There are lots of real-life errors that come out of these errors and the worse mistakes people make trying to work around control flow (goto fail?).

I desperately want a 'break break' command. Not a label break, which is painful to work with, but an instruction to break the current loop and the outer loop.

Re:Loop Exits and Structured Programming: Reopening the Deba... by mort96 on Monday June 12, 2017 @10:13PM (#14542476)
I don't like the goto fail thing being discussed as an example of goto being evil. If they had used the other common pattern - returning -1 on failure - instead of the pattern they used, their code would look like this:

  if (a)
      return -1;
  if (b)
      return -1;
      return -1;
  if (c)
      return -1;
  return 0;
And literally the exact same issue would occur, even though goto wasn't used.
Re:Loop Exits and Structured Programming: Reopening the Deba... by danthemanvsqz on Monday June 12, 2017 @04:25PM (#14540789)
Wrap the double loop in a function/method and return from the inner loop.
Re:Loop Exits and Structured Programming: Reopening the Deba... by Animats on Monday June 12, 2017 @04:33PM (#14540871)
That works well except when you're in a language where you can't nest functions and need data from the outer scope. C is like that.

Rust really likes to bail out of functions when something goes wrong. That's what "try!()" does.

Allowing multiple exits from a loop is no longer controversial. Multiple entries into a loop are still considered undesirable.

From a proof of correctness standpoint, the topology requirement is that there be some single place within the loop through which control must pass. That's where the proof inductive step takes place, and where you prove loop termination by showing that some measure is decreasing. Restrictions stricter than that are more stylistic than formal.

Re:Loop Exits and Structured Programming: Reopening the Deba... by graycat on Monday June 12, 2017 @05:02PM (#14541086)
Ah, you seem to be talking about having the source code of function X inside the source code of function Y and, then, the names known in function Y are also known in function X unless declared again within function X. I LIKE that! That's what PL/I has.

Once I got a phone interview from Google. An early question was,

"What is your favorite programming language?"

Sure, right away, PL/I! Opps, (from a movie) "way wrong answer!". Apparently the only right answer was C++. Gee, I didn't want to lie. Besides, to me saying C++ instead of PL/I should cause me to lose a full letter grade!

So, PL/I has descendancy, static and dynamic. The static version is from the nesting in the static source code. The dyanmic version is from functions, subroutines, etc. that have been called (are active) but have yet to return.

Then with such descendancy and entry variables, can get some interesting situations, design patterns!

I did that once and avoided a total mess in the IBM AI language KnowledgeTool!

Re:Loop Exits and Structured Programming: Reopening the Deba... by eru on Monday June 12, 2017 @05:25PM (#14541260)
In GCC's C you can nest functions. (But that's not portable.)
Re:Loop Exits and Structured Programming: Reopening the Deba... by lacampbell on Monday June 12, 2017 @04:25PM (#14540794)
For me 'break break' is usually just return. My small brain gets overwhelmed when I'm nested any deeper than that.
Re:Loop Exits and Structured Programming: Reopening the Deba... by jstimpfle on Monday June 12, 2017 @04:57PM (#14541052)
Two nested loops are often ok. Now put some cleanup code after that...
Re:Loop Exits and Structured Programming: Reopening the Deba... by erikpukinskis on Monday June 12, 2017 @05:56PM (#14541451)
Can't you just set flag = true and then if (flag) { break }?
Re:Loop Exits and Structured Programming: Reopening the Deba... by btilly on Monday June 12, 2017 @06:41PM (#14541713)
What makes a label break painful to work with for you?