One method to achieve your target would be to use a program 'while' statement.
First function (delta) will run the loop a given number of times & I have matched the iterations with your example so the result appears to be correct.
The next function (delta2) modifies this to loop until convergence.
It is possible for this to loop for ever so a counter to limit the max number of iterations is advised.
You will need to define the convergnce condition that you require, at the moment it is a simple sum of differences squared.
Hope this is helpful
Regards
Andy