Here is what I currently use to break out of a double loop and proceed with DoStuff():
foreach (var enemyUnit in nearbyEnemyUnits) {
var skip = false;
foreach (var ownUnit in ownUnits) {
if (ownUnit.EngagedTargetTag == enemyUnit.tag) {
skip = true;
break;
}
}
if (skip) continue;
DoStuff(enemyUnit);
}
The whole "defining a temporary boolean variable to check for a skip" seems very hacky to me. In a language like Go I can use labels to break out of loops, or even make the inner loop part of a clojure. What is the best way to do this in C#?
I've been doing it like the above example for the longest time and feel like there must be a better way - almost ashamed to ask at this point.
Thank you