The first return
in the following method does not end the method, but instead breaks out of the loop
boolean isAnyColorRed() {
colors.each {
if (it.type == "red")
return true // does not end the method but instead breaks the loop.
}
return false
}
What is a workaround? This?
boolean isAnyColorRed() {
boolean foundRed = false
colors.each {
if (it.type == "red") {
foundRed = true
return //break the loop
}
}
if (foundRed)
return true
else
return false
}