You may also be interested in zip: for (file, i) in zip(files, 1:length(files)) println(file, " ", i) end
# Even better: using Lazy for (file, i) in zip(files, range()) println(file, " ", i) end Enumerate is definitely the best solution here, but zip is more general if you find yourself bumping against similar problems. On Thursday, 15 May 2014 14:00:09 UTC+1, Michele Zaffalon wrote: > > What about enumerate: > http://docs.julialang.org/en/latest/stdlib/base/?highlight=enumerate#Base.enumerate? > > > On Thu, May 15, 2014 at 2:48 PM, Yakir Gagnon <[email protected]<javascript:> > > wrote: > >> I love the >> for file in files >> ... do something with file ... >> end >> >> syntax. But sometimes it's really useful to be able to have an iterator >> accessible in the for loop, like: >> >> for file in files >> ... do something with file ... >> ... and with i that equals find(file == files) ... >> end >> >> >> Is there something built in like that, other than the usual way of: >> >> for i = 1:length(files) >> ... do something with files(i) ... >> ... and with i ... >> end >> >> ? >> > >
