increment i before comparing with array length