From: 7stud -- Date: 2008-02-14T11:10:23+09:00 Subject: Re: my noob "numbering lines" programe. How to improve? Adam Akhtar wrote: > > totalnumlines = File.readlines(infilename).length > numdigits = 1 > x = 1 > while (x < totalnumlines) > x = x * 10 > numdigits = numdigits + 1 > 1) Suppose totalnumlines = 3. The last time through your while loop, x will equal 2--if x is equal to 3, the loop will terminate and not execute again. So the assignment to x inside the loop will assign 2*10= 20 to x. So why not just do this: x = (totalnumlines - 1) * 10 There's no need for any loop to calculate x. 2) Once again suppose totalnumlines = 3. That means the loop will execute twice: the first time when x =1 and the second time when x=2. When x =3, the loop will terminate before it executes again. Therefore, numdigits will equal 3, which is the same value as totalnumlines. So you can just write: numdigits = totalnumlines -- Posted via http://www.ruby-forum.com/.