Hacker News new | ask | show | jobs
by danthemanvsqz 3292 days ago
Wrap the double loop in a function/method and return from the inner loop.
1 comments

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.)