Skip to content

Instantly share code, notes, and snippets.

@c4tachan
Last active December 30, 2015 03:59
Show Gist options
  • Save c4tachan/7772853 to your computer and use it in GitHub Desktop.
Save c4tachan/7772853 to your computer and use it in GitHub Desktop.
I recently saw this algorithm in a coworker's code, and I was confused by how he used the continue statement on line 18. It seems to me that the continue will only cause the inner foreach loop to continue and not the outer loop which is what I believe was the intention.
foo[5] a = { 1, 2, 3, 4, 5 }; //foo is a type
foo[3] b = { 1, 2, 3 };
List<foo> unMatched = new List<foo>();
foreach (foo c in a)
{
bool wasMatched = false;
if(0 != c)
{
foreach (foo d in b)
{
if(c == d)
{
wasMatched = true;
continue;
}
}
}
if(!wasMatched)
unMatched.Add(c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment