I mean one dirty workaround would be to work with something like:
for i in 1:10
do_something(Val(i))
end
This lifts the number to the type domain but it will result in (slow) dynamic dispatch since Val(i) is in the type domain but it’s type is runtime depending on the for loop. Slow of course can be relative.
But @generated should be able to work with it. I think you need to figure out how the exact syntax with @generated and @nloops combines.
Again to repeat: This is not really Julia idiomatic and CartesianIndex iterators would be more clear. Perhaps also some sort of recursive algorithms.