Do the loop terminates when it qualifies the return statement? even when value is null?
Asked
Active
Viewed 62 times
1 Answers
0
Your question is too vague to be answered with any kind of certainty. Were I to hazard a guess, however, I'd bet you're referring to control statements within a '.each' loop?
If so, the short answer is: No, return (or break) does not terminate the loop. The only way to do so is via throwing an exception within the loop à la:
try{
(1..10).each{ n->
println n
if (n == 5) throw new Exception()
}
}
catch(Exception){}
But, this is a total abomination. Use a for or while loop instead.
See also: returning from closure
If I'm off the mark, perhaps you could post some code exemplifying your topic?