Recently I needed N (a variable number of) nested for-loops. A vector len contained the max counter of each loop.

The dumb way would have been this:

```
if n==1
for a=1:len[1]
# Loop body
end
elseif n==2
for a=1:len[1], b=1:len[2]
# Loop body
end
# ... and so on
```

Instead, here’s what I came up with, which at least is less dumb:

```
a = ones(Int64,n)
a[n] = 0
breakwhile = false
while true
for k=0:n-1
if a[n-k] < len[n-k]
a[n-k] += 1
break
elseif n-k == 1
breakwhile = true
break
else a[n-k]=1 end
end
breakwhile && break
# Loop body goes here.
end
```

It was fun coming up with that and it worked, but I feel like this situation arises often enough that, in a perfect world, there would be a macro or command for it.

Maybe something like “@nest for k in v”

where v is a Vector{Int64} of the loop durations, and k is a vector of counters (created locally if not already existing).

Is this just noob babbling, or a good idea? Does it already exist in some form? If not, perhaps I’ll take a stab at making a macro.