Re: why is 0 first?



> I am curious what the reasoning behind the first element of
> something being zero is ($array[0]). I know I've read it before, but
> I can't remember. Thanks!

Using indices 0 .. n make it possible to work with them like offsets
from the beginning of the array. More important from a C point of
view, where it may even improve performance. Ah, and for loops are
shorter by one character ;)

for ( $i=0; $i<$n; $i++ ) { .. }

rather than

for ( $i=1; $i<=$n; $i++ ) { ... }
.



Relevant Pages

  • Writing a character to the beginning of the same file
    ... I have program that pre-appends a character to a file. ... a temporary byte array and add the new character to be added to another ... Prev by Date: ...
    (comp.programming)
  • Re: Space (s) count problem
    ... > character (into an array) until the white space is reached. ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: Getting bytes from a string
    ... the GetBytes method works ok. ... But it takes each character as an ... > element of the array. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Getting bytes from a string
    ... the GetBytes method works ok. ... But it takes each character as an ... element of the array. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Need help with textboxes
    ... character into the input box. ... one of assigning the reference to a variable: ... All forms and their children are stored in an array ... No. Bracket property accessors allow their argument to be any string value. ...
    (comp.lang.javascript)