split loops that take too long to execute. accepts array, max index, function and optional callback