start at 0 or 1

edited December 2014 in General Discussion

The line has 3 segments: Screen Shot 2014-12-18 at 5.40.37 PM

Let's say I have a method

float length(int segment) {
  // returns length of segment
}

Then should I start counting at 0 (like 0,1,2)? Or start at 1 (1,2,3)?

Answers

  • Answer ✓

    Generally I would suggest that you start at 0 since the first element in ANY sequential Java collection or array is zero.

    For a more informative answer you might explain how are you storing the segment data e.g. an array of vertices, or a class to hold segment data or something else.

  • length is 3. but if the lines are numbered they are lines 0, 1, 2.

  • but what is 'segment' argument for?

  • thx zero it is.

    segment, is what part of the line you mean.

Sign In or Register to comment.