Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



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.


Wrap the double loop in a function/method and return from the inner loop.


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.


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!


In GCC's C you can nest functions. (But that's not portable.)


For me 'break break' is usually just return. My small brain gets overwhelmed when I'm nested any deeper than that.


Two nested loops are often ok. Now put some cleanup code after that...


Can't you just set flag = true and then if (flag) { break }?


What makes a label break painful to work with for you?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: