[Tutor] Generic For Loop

bob gailer bgailer at gmail.com
Thu Oct 13 02:56:59 CEST 2011

On 10/12/2011 8:41 PM, Max S. wrote:
> I've been doing some research into C++, and I've noticed the for 
> loops.  Is there a way to use the C++ version of the loops instead of 
> the Python one?  For example, I believe that the Python syntax would be:
> for a=1, a < 11, a += 1:
>     print(a)
> print("Loop ended.")
> if the 'for' keyword did it's function as in C++, Actionscript, or 
> most other programming languages.  Is there a way to do this?

for i in range(1, 11, 1): # the final 1 can be omitted, as it is the 
default value.
   loop body


i = 1
while i < 11:
   i += 1
   loop body

Your choice - that's all know of - and the for is easier to read and 
write than the while.

Bob Gailer
Chapel Hill NC

More information about the Tutor mailing list