Custom Variable does not change after iteration

You are not overwriting the variable, rather you are re-declaring it. Also in your code above you have missed a curly bracket i.e. { if le $loaded 10 }}

See this post about overwriting variables:

Hint: you declare a variable with := then you overwrite it with =