The "loop and a half"
Ben Bacarisse
ben.usenet at bsb.me.uk
Wed Oct 4 08:34:27 EDT 2017
ram at zedat.fu-berlin.de (Stefan Ram) writes:
> Steve D'Aprano <steve+python at pearwood.info> writes:
>>For-each loops are MUCH easier to understand, and should be taught first.
>
> I prefer a bottom-up approach.
>
> For loops are based on iterators.
>
> So, "bottom-up" in this case means: iterators should be
> taught before for-loops.
>
> But iterators are too abstract to be taught very early.
I think this may be a problem with your style. From your other
postings, I think you value precision and exactness over broad
understanding, and maybe you teach like that.
I my view, it's possible to explain enough about iterators to understand
a huge range of for loops without having to go into the gory details. I
find the image of a conjurer pulling knotted hankies out of a hat a good
one -- they may go on forever and you don't know if there is rabbit in
there knotting them and deciding which colour comes next.
> But I will teach iterators and for loops not much later than
> while-loop.
>
> Maybe this way: Use a while-loop and try-catch to get values
> from an iterator until exhausted, and then introduce the
> for-loop as an abbreviation for that.
That sounds very complicated, but I think I favour the other extreme to
you.
--
Ben.
More information about the Python-list
mailing list