jeudi 31 décembre 2020

Return Value inside if statement inside for loop inside function

My goal in the below code is to cycle through the IF statement and have the function return a True value if the IF statement holds true throughout all the iterations? If during any iteration the evaluation is false I want to immediately return False. Am I writing this correctly? I get confused with the order of operations within the IF statement. Is there a simpler more elegant way to write this?

function checkGroup($groupNum, $names, $namesNow, $$group, $groupSize, $i){
  for ($m=0; $m < count($$group); ++$m){
    //checks to make sure current person doesn't conflict with anyone else in current group
    if ($namesNow[$names[$i]][$$group[$m]] < $max ){
      continue;
    }
    else {
      return false;
      break;
    }
  }
  return true;
}

Aucun commentaire:

Enregistrer un commentaire