I want to run something like this:
For a = 0 To 4
For b = a To 4
For c = b To 4
Console.WriteLine(a & b & c)
Next
Next
Next
But I need to create n loops one each other. So I created this method:
'iFrom = 0; iTo = 4; Depth = 3(loop count);
Private Sub Iterate(ByVal iFrom As Integer, ByVal iTo As Integer, ByVal Depth As Integer)
For i = iFrom To iTo
If Depth - 1 > 0 Then Iterate(iFrom, iTo, Depth - 1)
'Do stuff here
Next
End Sub
What would be the best way to retrieve the “i” values from higher levels? Should I store them in an array? Or is there a completely different way to approach this problem?
After playing around with this method I finally found the solution. Here it is: