... How to choose between it's and its?
This is actually really easy, do you mean "it is" or not?
Use it's when you mean it is.
// Each element is the ASCII for it's index.
Here you should write its because you mean possession, intended as a property of the element.
Saying that:
// Each element is the ASCII for it is index.
Makes no sense.
So the correct comment will be:
// Each element is the ASCII for its index.