This is an example from Java in Two Semesters 6.8.3
static boolean containes(int[] arrayIn, int valueIn)
{
for (int currentElement : arrayIn)
{
if (currentElement == valueIn)
{
return true; // exit loop early if value found
}
}
return false; // value not present
}
It says that the RETURN TRUE will exit the loop early, meaning it won't return false as in the later line. I really can't seem to get my head around how it exists the loop rather than return BOTH true and FALSE, i.e., as i'ts not a 'for... else' loop, wouldn't the code just go through the next command below? Thanks for your help!