[Tutor] Re: Request for code critique ['break' vs control flag]

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Oct 22 18:58:25 EDT 2003



On Wed, 22 Oct 2003, Alan Gauld wrote:

> > >         while primes[n]<=limit and len(candidates)>0:
> > >             limit=int(candidates[0]**0.5)
> > >             if candidates[0]%primes[n]==0:
> > >                 del candidates[0]
> > >                 n=0
> > >             n=n+1
>
> > well. Also I think that your while-solution is not as pythonic as it
> > could be (making it harder to follow for me). It's more common to use
> > a break statement than to define a loop variable outside the
> > while-loop:
>
> While that's a frequently seen Python thing I'm not sure its necessarily
> a good thing. Break is one of those features introduced into C (and
> whence into many other languages) which breaks the rules of structured
> programming and by so doing makes code more difficult to read reliably.

Hi Alan,

On the other hand, the Refactoring folks talk about --- and encourage! ---
the use of 'break' with their section on "Remove Control Flag (245)".

But I've also met a lot of respected programmers who insist on the "one
entry point, and one exit point" viewpoint. 'break' drives them crazy.

So, like many style guidelines, it's a controversial issue. *grin*




More information about the Tutor mailing list