Skip to content

Instantly share code, notes, and snippets.

@dornatsky
Created June 23, 2011 15:33
Show Gist options
  • Save dornatsky/1042777 to your computer and use it in GitHub Desktop.
Save dornatsky/1042777 to your computer and use it in GitHub Desktop.
Will run a for loop of an arbitrary nesting depth
public class ForLoop
{
private int[] _indices;
private int[] _boundaries;
private Action<int[]> _action;
public ForLoop(int[] indices, int[] bondaries, Action<int[]> action)
{
_indices = indices;
_boundaries = bondaries;
_action = action;
}
public void Run()
{
for (int i = 0; i < _indices.Length; i++)
{
int length = _boundaries[i];
for (; _indices[i] < length; _indices[i]++)
{
_action(_indices);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment