for loops performance improvement

Hi,
I tried use little for-loops improvements.
Tests over mysql passed.