lundi 23 novembre 2015

If statement in a nested loop logic

I am struggling with some logic. I have a nested for loop with an if statement inside.

foreach(object in list)
 foreach(otherObject in otherList)
  if(object.name == otherObject.name)
   foo();
   break;
  else
   bar();

This will do bar() everytime the if statement is false. How can I do bar() only if foo() is never done? Apologies if this a repeated question, which it probably is...

Aucun commentaire:

Enregistrer un commentaire