Preventing script from breaking

Looping until the last index of the array