unintuitive for-loop behavior

Grant Edwards grant.b.edwards at gmail.com
Fri Sep 30 12:43:29 EDT 2016


On 2016-09-30, Grant Edwards <grant.b.edwards at gmail.com> wrote:
> On 2016-09-30, Steve D'Aprano <steve+python at pearwood.info> wrote:
>
>> To me, "make for-loops be their own scope" sounds like a joke
>> feature out of joke languages like INTERCAL. I'm not aware of any
>> sensible language that does anything like this.
>
> In C99 a for loop has its own namespac:
[...]
> I think that's an absolutely brilliant feature, and I use it a _lot_
> when writing C code.  I'm a big fan of minimizing the lifetime/scope
> of variables. I wish if/then/else did the same thing:
>
>   if ((r=some_function()) != R_SUCCESS)
>     printf("some_function() failed with status %d\n",r);

The example of what I wished C did should have been this:

   if ((int r=some_function()) != R_SUCCESS)
     printf("some_function() failed with status %d\n",r);


-- 
Grant Edwards               grant.b.edwards        Yow! If I pull this SWITCH
                                  at               I'll be RITA HAYWORTH!!
                              gmail.com            Or a SCIENTOLOGIST!




More information about the Python-list mailing list