for / while else doesn't make sense
BartC
bc at freeuk.com
Fri Jun 3 05:32:54 EDT 2016
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. And that is iterating over a fixed set of values. E.g. in Python
>
> for rendering in (False, True) :
> ...
> #end for
>
> versus the (slightly) more long-winded C:
>
> for (bool rendering = false;;)
> {
> ...
> if (rendering)
> break;
> rendering = true;
> } /*for*/
>
Just one case? Python is miles away from a C 'for'. There's:
- C's for loop, a glorified while loop where you have specify every
single detail: for (i=a; i<=b; ++i), including writing your nominated
loop index three times.
- A 'traditional' for loop, which iterates over the integers A to B or 0
to N-1 without having to spell out everything: for i=a,b
- A 'forall' kind of loop which iterates over a set of values, which is
what Python has: for i in x:
--
Bartc
More information about the Python-list
mailing list