Skip to content

Instantly share code, notes, and snippets.

@SimonPStevens
Created June 21, 2017 20:38
Show Gist options
  • Save SimonPStevens/382633f5f9e3b55894b6f906319d8a2f to your computer and use it in GitHub Desktop.
Save SimonPStevens/382633f5f9e3b55894b6f906319d8a2f to your computer and use it in GitHub Desktop.
A little for each helper to do for each loops either to the end or until a condition is met.
public static class ForEachHelper
{
public static void ForEachUntil<T>(IEnumerable<T> enumerable, Func<T, bool> until, Action<T> loopInner)
{
var enumerator = enumerable.GetEnumerator();
while (enumerator.MoveNext() && !until(enumerator.Current))
{
loopInner(enumerator.Current);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment