• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sum of array elements?  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering what's the difference between i < array.length and i <= array.length??
Why does i <= give me error?



Please, can somebody explain?
 
Sheriff
Posts: 4756
133
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If an array has a length of 7, it will have elements 0 through 6. As soon as i equals the array length, it will try to access the 7th element, which isn't there.
 
Stephan Crandego
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:If an array has a length of 7, it will have elements 0 through 6. As soon as i equals the array length, it will try to access the 7th element, which isn't there.



Thanks! That explains everything
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!