using range() in for loops

John Salerno johnjsal at NOSPAMgmail.com
Wed Apr 5 10:07:55 EDT 2006


Roel Schroeven wrote:

> In many cases loops really are for iterating over sequences; more so 
> than I realized when using for loops in C or C++. In these cases, 
> Python's for statement works better than C-style loops. And if you 
> really need to do something a certain number of times, there's still 
> range() or xrange() to do it.

Yeah, I'm starting to see the distinction now. I think one thing that 
confused me was that C# had two separate loops for these 
functionalities, the for loop and the foreach loop (which is equivalent 
to Python's for). But even when just doing something a number of times 
(C#'s for, Python's for), it looks much cleaner in Python because you 
don't have the long, messy three-part for statement.



More information about the Python-list mailing list