In the fuction Replace[expr,rules,levelspec], levelspec may be a variable:
Given:
g = {{{a, b}}, {a, b}, c}
locVar = {a, b}
Replace[g, locVar -> 10, 1]
Here 1 is the levelspec, run Replace[g, locVar → 10, 1] will:
{{{a, b}}, 10, c};
run
Replace[g, locVar -> 10, 2] :
{{10}, 10, c}
Replace[g, locVar -> 10, n] /. n -> {1, 2}:
{{10}, 10, c}
But how to iterate n?
run
Do[Replace[g, locVar -> 10, n], {n, 1, 2}]
, no result,why?