I would rewrite this:
while (foo() == true) { foreach (var x in xs) { if (bar(x) == true) { //"break;" out of this foreach //AND "continue;" on the while loop. } } //If I didn't continue, do other stuff. DoStuff(); }
a
while (foo()) // eliminate redundant comparison to "true". { // Eliminate unnecessary loop; the loop is just // for checking to see if any member of xs matches predicate bar, so // just see if any member of xs matches predicate bar! if (!xs.Any(bar)) { DoStuff(); } }
source share