bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why should `break' and `continue' in functions not break loops runni


From: Greg Wooledge
Subject: Re: Why should `break' and `continue' in functions not break loops running outside of the function?
Date: Sat, 30 Oct 2021 09:49:39 -0400

On Sat, Oct 30, 2021 at 02:39:19PM +0300, Oğuz wrote:
> I found that this behavior had been introduced in 2014, with the
> following commit message:
> 
> > set loop_level to 0
> > when entering a function so break and continue in functions don't
> > break loops running outside of the function. Fix picked up from
> > dash
> 
> and the commit message for the fix in question reads:
> 
> > As it is if you do a multi-level break inside a function it'll actually
> > include loops outside of the function call. This is counterintuitive.

> So, does anyone know a case where the new behavior can be useful/the
> old behavior can be harmful? Am I missing an obvious problem with the
> old one?

As Chet said, it's counterintuitive.  Most people don't expect function A
to be able to affect loops inside function B.  It's a violation of scope.

Can you name *any* other language where functions can break out of their
caller's loops?  The only thing that comes to mind for me is C's "longjmp",
which I've never used even once.  (Not that I do any C programming these
days, but back in the 1990s, I did.)

What are you actually trying to do?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]