Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49164
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Is this PEP-able? fwhile |
| Date | 2013-06-25 10:28 -0400 |
| References | <8D03F2B8CF0E7BE-1864-1796B@webmail-m103.sysops.aol.com> <CAN1F8qV1SvhpZO0DpBOqEoQ_quB4t0=LhZLc1i+XUkPnCvuiGw@mail.gmail.com> <8D03FACACE891AA-D84-26FBE@webmail-vm008.sysops.aol.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3833.1372170531.3114.python-list@python.org> (permalink) |
On 6/25/2013 7:17 AM, jimjhb@aol.com wrote:
> for i in range(n) while safe(i): ..
Combined for-while and for-if statements have been proposed before and
rejected. We cannot continuously add simple compositions to the langauge.
> I disagree. The problem IMO is that python 'for's are a different kind
> of 'for' in that they have no explicit indexing and no explicit range
> test; just a list which has elements drawn from it. This is amazingly
> powerful and concise. Unfortunately, the "breaks are just gotos"
> community often ruins this conciseness by going to 'while' or itertools
> (or worse) to avoid adding a break to a 'for' which needs to be
> terminated early.
'Break' and 'continue' were intended to be used ;-).
> I think suggestions like yours and Fabio's are good ones. If 'for' has
> an 'else', why not a 'while'?
While-else and for-else follow from if-else. Which is to say, the else
corresponds to the buried if that is part of while and for. The else
part triggers when the if part is false. The difference from if-else is
that the if part is tested multiple times.
while condition():
block()
else:
finish()
is equivalent to
while True:
if condition():
block()
continue
else:
finish()
break
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Is this PEP-able? fwhile Terry Reedy <tjreedy@udel.edu> - 2013-06-25 10:28 -0400
csiph-web