how to write a C-style for loop?
John Salerno
johnjsal at NOSPAMgmail.com
Wed Feb 15 09:52:49 EST 2006
Tim Roberts wrote:
> John Salerno <johnjsal at NOSPAMgmail.com> wrote:
>> I assume this is the way for loops are written in C, but if it helps to
>> be specific, I'm referring to C# for loops. The Python for loop seems to
>> be the same (or similar) to C#'s foreach loop:
>>
>> foreach int i in X
>>
>> But how would you write a C# for loop in Python? Do you rework a while
>> loop, or use the range() function?
>>
>> Here's an example:
>>
>> for (int i = 0; i < 50; i += 5)
>>
>> How would that go in Python, in the simplest and most efficient way?
>
> for i in range(0,50,5):
> print i
Thanks guys. I thought it might be something like this. In fact, the
chapter I just read dicussed how you use the range function with a for
loop, but I didn't quite see a connection with the C# for loop.
More information about the Python-list
mailing list