Re: missing values from files



Chas Owens wrote:
On 7/30/07, John W. Krahn <krahnj@xxxxxxxxx> wrote:
Chas Owens wrote:
On 7/30/07, Isha M. Renta <isha.renta@xxxxxxxxx> wrote:
The 13 is the counter for the $inittime array (which actually have 13
numbers and not 15 as it seems) and the 3600 is the number of lines in all
the files. All the files have 3600 lines.

Isha
snip

Then you have an off-by-one error. You are saying

for($j=0;$j<=13,$j++) {

This will loop 14 times, not 13 times. This is why C-style for loops
are bad. Don't use them. If you want to loop over an array use the
iterating version of for:

for my $element (@array) {}

If you want to loop over a range you still should use the iterating
version of for:

for my $j (1 .. 13) {}
It would probably be better to use:

for my $j ( 0 .. $#array ) {}
snip

No, that is almost always better written as

for my $element (@array) {}

That is a completely different loop. And I think John's point was that
it would be better to use $#array than to hard-code 13.

Rob
.



Relevant Pages

  • Re: Iterate through member variables of a class
    ... I did that because the OP was asking about iterating through member ... variables of a class by using a while loop. ... you can add or remove elements from the array and the ... So it would be better if I declared the int as a size_t instead? ...
    (comp.lang.cpp)
  • Re: Holding Returned Data in Arrays
    ... whether or not new items are available whilst you loop depends on the ... implementation of the thing you are iterating. ... In the case of Getfiles() you can see that it returns an array. ...
    (microsoft.public.dotnet.framework.clr)
  • RE: Problems Loading Large String Array into Array variable
    ... Splitfunction rather than iterating the array with a For..Next loop? ... "ExcelMonkey" wrote: ...
    (microsoft.public.excel.programming)
  • Re: missing values from files
    ... This will loop 14 times, ... If you want to loop over an array use the ... You should only use a range if you want to iterate a specific number ...
    (perl.beginners)
  • Re: help executing a list
    ... (This is my first lisp program) ... in a loop, iterating over my arguments. ... array operator do not change in the loop. ...
    (comp.lang.lisp)