for / while else doesn't make sense

BartC bc at freeuk.com
Fri Jun 3 05:23:54 EDT 2016


On 03/06/2016 02:05, Lawrence D’Oliveiro wrote:
> On Friday, June 3, 2016 at 8:52:52 AM UTC+12, BartC wrote:
>> One major objection was that C's 'for' isn't really a for-statement at
>> all (as it is understood in most other languages that haven't just
>> copied C's version), but is closer to a 'while' statement.
>
> Apart from having local loop variables that get initialized just once. Not something you can fake with a “while” statement.

It's not hard. For:

   for (int A=B; C; D) {BODY}

you just write:

   {int A=B;
    while (C) {
      BODY;
      D;
    }
   }

>
> That’s what makes C’s for-statement so versatile.
>

That's if you're into that. I've only ever use local variables with 
function-wide scope.

If your concern is with optimising, other languages can just have a rule 
about the validity of a for-loop index variable when the loop 
terminates. That's impossible in C because, it being so general purpose, 
there is no such thing as a for-loop index:

   a=0; b=1;
   for (c=2; d<e; ++f) {...}

which one is the loop index? So it is necessary to stick actual 
declarations within the loop. Messy.

(Sorry, we're getting away from Python somewhat!)

-- 
Bartc



More information about the Python-list mailing list