I am confused with the following code.
func allTestsPassed(tests: [Bool]) -> Bool {
for test in tests {
if test == false {
return false
}
}
return true
}
If the code within the if-else statement (within the for-in loop) executes, it returns false.
But the code following the for-in loop is: return true.
Two different boolean values returned within a function.
When I execute print(allTestsPassed([false])) it prints 'false'.
It seems to disregard the 'return true' that follows the loop.
I do not understand.
return stop the process there and don't execute anything after it. It simply stop the process there.
To understand more let's update logic and see results.
Case 1 : All input is true
Now let's try
case 1where all input will betrueResults is
Case 2 : One of the input is false
Result is
If you see in second case you don't see
end of logicbecause it do the return whentest=falseHope the logs will clears your understanding...