Hi Karin,

My favourite metaphor is similar to the ones given already, I just flip
pages on a book.  I like the book analogy because the action could be, read
the page, search for a string or fill the "o"s.  Additionally, since the
books have page numbers I could get the "index" too (ie. enumerate) - but I
don't explain the two examples at the same time, the I introduce the
`enumerate` function to people is already confident with the loop.

book is a collection (list) of pages

for page in book:
    read(page)

for page_number, page in enumerate(book):
    ...

Hope it helps,
David


On 3 December 2015 at 09:24, Karin Lagesen <[email protected]> wrote:

> The more I teach, the more I realize that I am not really able to convey
> what a for loop does to everybody. Do any of you have a metaphor or
> something that you use for teaching it? I explain about variables and
> collections, and the body of the loop, and I show examples, but I am still
> not able to get through all the time.
>
> Karin
>
> _______________________________________________
> Discuss mailing list
> [email protected]
>
> http://lists.software-carpentry.org/mailman/listinfo/discuss_lists.software-carpentry.org
>
_______________________________________________
Discuss mailing list
[email protected]
http://lists.software-carpentry.org/mailman/listinfo/discuss_lists.software-carpentry.org

Reply via email to