On Sun, 3 Sep 2006 at 8:21pm, Bram Moolenaar wrote: > > Hari Krishna Dara wrote: > > > On Sun, 3 Sep 2006 at 12:53pm, Bram Moolenaar wrote: > > > > > > Can't you use something like: > > > > > > for loop_index in range(1, 10) > > > <body> > > > endfor > > > > As I said in my reply to Tony, this is inefficient when the range is > > big, > > What performance degradation have you noticed then?
I am not saying I noticed any, but just anticipating. E.g., using range() to iterate over all lines of a huge file (having 1000's of lines) very often would result in creating this list of numbers multiple times, just seems like an overkill. > > and to avoid this problem Python has irange() which is an > > enumeration. Now adding enumerations to Vim will be a non-trivial > > change (and unnecessary complication, as we are not trying to achieve a > > full fledged scripting language), but adding a for loop variant should > > be much simpler. > > I looked into something like Python's xrange(), but it's a messy solution. > And I don't think it actually improves the performance. > > I don't know what irange() is. I only find something about it in a > rejected PEP. Sorry, I meant xrange(), I somehow remembered it as irange(), my bad. Why don't you think it improves performance in this case? All that xrange() in this case would do is to keep track of the current number and return the next one in every call, there is no temporary list involved. > I don't know what you mean with "loop variant". I meant creating a variation of the existing :for loop syntax which can work with loop indexes. -- Thanks, Hari __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com