Thank you Superku,
I ultimately decided to build a material for each layer count and forget about dynamic loops.
By the way I tryed to add an integer to the material through SetInt DX function. It fails in the compilation too. I am pretty confused because iLights or iWeights are also integers containing dynamic ranges and are commonly used into for loops with no troubles.
i força al canut