Return statment inside or outised for loop

Tell us what’s happening:
I have finished the “Intermediate Algorithm Scripting: Everything Be True” challenge, but I noticed that when I would put my return statement inside the for loop I would get a different result than when I would put it outside. I would get it wrong.

I understand once the if statement condition is met the result variable is assigned a false value, but how-come when the return statemnt is inside the for loop, the last boolean value is returned instead of staying false once the false condition is met. When the return statement is inside the for loop why does it return the value of the last result. And when its outside it saves the value once the if statement conditions are met

For example if the last element does not meet the false conditions (if statements) and the return value is inside the for loop result is returned as true, even though one or more of the proceeding statements returns false. But if the return result statement is outside the for loop, once of the if statement condition the result value becomes false and stays false, no matter if any of the following element is true (not false).

Your code so far


function truthCheck(collection, pre) {
  let result = true;
  for(let i = 0; i < collection.length; i++)
  {
    let element = collection[i]
    if(element[pre] === " ")
    {
      result = false;
    }

    if(!Boolean(element[pre]))
    {
      result = false;

    }
  
  }

  return result

}


truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36.

Challenge: Everything Be True

Link to the challenge:

when the return statement is executed the function stops

so if you put it inside a loop you will stop the loop from iterating over all the array