[Tutor] Generic For Loop

Max S. maxskywalker1 at gmail.com
Thu Oct 13 03:08:04 CEST 2011


Thanks!

On Wed, Oct 12, 2011 at 8:56 PM, bob gailer <bgailer at gmail.com> wrote:

>  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
>
> OR
>
> 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
> 919-636-4239
> Chapel Hill NC
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111012/ca48ba5c/attachment.html>


More information about the Tutor mailing list