I think that this what you want see:
This into winxp sp3 with mathcad 11 eating 23460 Kb, as report task manager.
I have the following rule: "if the iterating number is knowed, then must to be a for loop ... ". Next is the exception: .. except that you can vectorize."
There is a thing that I not understand: can't you check which is first,next...last before the for loop?
You testing file coul be more interesting if you put it in the "real" math world. Here an interesting example:
Try to write the usual procedure for the bisection method for the zero of a monodic function, i.e. using while abs(b-a)>TOL and then try to write one other using a for loop. Notice that the iteration number is given for this algorithm.
Then call the zero's routines for a lot of functions (probably a parametric family to not write dozens of code pages) or call over the same function a lot of times to find the same zero to amplify the bussy time.
That's as suggestion.
Regards. Alvaro.