[Tutor] FOR loops

Emile van Sebille Emile van Sebille" <emile@fenx.com
Sat, 2 Oct 1999 11:26:19 -0700

Hello R.,

For loops provide you a way to apply the same logic to a number of
items.  For example, to count the number of vowels in a string:

>>> test = "this is a test string"
>>> count = 0
>>> for letter in test:
 if letter in 'aeiou':
  count = count + 1
>>> print count

or to add up the first 100 numbers:

>>> total = 0
>>> for i in range(100):
 total = total + i
>>> print total

or, more generally:

for each in things:
    do something


Emile van Sebille

PS: My spell checker objected to count and total where they appear after
the '=' above.  Any ideas why?

My-spell-checker-practices-Heisenberg-ly y'rs - Emile


----- Original Message -----
From: R Parker <spiderman@nasachem.com>
To: <tutor@python.org>
Sent: Saturday, October 02, 1999 8:07 AM
Subject: [Tutor] FOR loops

> Hello, I am a beginner at python and have been learning it from the
> O'reilly book 'Learning Python'
> it has been pretty easy to understand for someone who has never
> programmed before, but it stumps me sometimes.......Thats where this
> message comes in, I got to the part that introduces FOR loops
> the book doesn't explain the concept very well and I don't understand
> how to use FOR loops in my programs.Could anyone explain what FOR
> do and how to implement them in my programming?? I would really
> appreciate it.
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor