You need to control the same at calling time... You need to make sure that passed index should be between 0 to index - 1 if index is 1 to index else
if index is starting from 0 then you can pass index directly
Jackson Daniels wrote:So should I make an if statement that basically says if index is >= number of vertices then return vertices[index].?
You could do that, but then you'd have to decide what to return if that test failed. I don't think that's what you're missing here, though. The way you "set" that parameter is by doing it before you call the method. An example which is simpler than Tushar's, a bit simpler anyway:
So here I have set the value of the parameter to 1. Of course I could have any kind of code at all which sets the value of the parameter, I could read it from the console or choose a random number or use a loop variable as per Tushar's examples. Does that help, or are we on the wrong track?