Why do we use `<` instead of `<=` in our for loop?


#1

Question

Why do we use < instead of <= in our for loop?

Answer

We use < because we do not want the index’s value to be equal to our array’s length. If this happens we’re at an index that’s right outside of the array, there’s nothing there. Remember, arrays are zero indexed, so the index equal to the length of the array is empty.