I have a function y=  f(x) . 
x is 10 x n  and y= 1 x n 
a performance function myperf = perf(y)  gives a 1 x 1 value. 
a target value mytar must be reached.
if mytar is not reached I must reiterate the process in this way :
and finally ...
So
 if myperf = perf(y) > mytar
 I must continue to the next iteration and rebuild the code for 2 for loops and so on.
I can't known how much iteration I'll need.
x dimension is 10^niteration x n ( 10 ,100 ,1000 ... 10^niteration)
I must pay attention to use intermediate results to not reinitialize the algorithm every time and loose resources.
What type of architecture cold I use ?
The most symple and understandable ? 
Is there a way for code autogeneration ?
Thanks !