Optimizes selected for loops

The corresponding for loops check the array length every pass through
although they do not change size, thus checking the length at the
beginning of the loop is much more efficient