From: Mohit Sindhwani Date: 2008-11-04T01:08:09+09:00 Subject: Re: Clean way of pausing a loop? Kyle Schmitt wrote: > It's Monday and it's relatively early, so I apologize if this isn't > worded too well. > > Is there a clean way of pausing a loop/printing status every N > iterations? I often use ruby to examine log files in a one-off > fashion, and when dealing with files of 4-10 million lines, this is > the sort of thing that becomes important. Small files are, obviously, > not as big of a deal. > > I know I can simply do this, but it doesn't seem clean: > > counter=0 > n=100 > foo.each do > |bar| > counter+=1 > if (counter%n).zero? > sleep 0.1 > end What's wrong with it? I can only think that if foo allows .each_with_index, you could avoid the counter initialization and addition. Can't think of anything else. Cheers, Mohit. 11/4/2008 | 12:09 AM.