Bounds check while looping over a fixed size table or array

(Edited to use existing ARRAY_LENGTH macro --nickm)
Avoid unsigned/sign compare warning from last patch.