git.net

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

for / while else doesn't make sense


On 03/06/2016 17:22, Lawrence D?Oliveiro wrote:
> On Friday, June 3, 2016 at 9:33:32 PM UTC+12, BartC wrote:
>> On 03/06/2016 03:47, Lawrence D?Oliveiro wrote:
>>> On Friday, June 3, 2016 at 8:52:52 AM UTC+12, BartC wrote:
>>>> Simple iterative for-loops are more of a DIY effort...
>>>
>>> There is one case that Python handles more nicely than C.
>>
>> Just one case? Python is miles away from a C 'for'.
>
> Yes, just one case. In Python you write a loop with one exit in one way, a loop with two exits in a different way, and a loop with more than two exits in yet another entirely different way. Can you say ?cognitive burden??

You mean like this:

  while True:
     if a: break

  while True:
     if a: break
     ...
     if b: break

  while True:
     if a: break
     ...
     if b: break
     ...
     if c: break

> The for-statement in C handles most of my looping requirements.

(Yeah, you might find that does 'if' and 'goto' does as well! As well as 
most other control flow statements including multi-level breaks.)

-- 
Bartc