-1

Do the loop terminates when it qualifies the return statement? even when value is null?

skaffman
  • 398,947
  • 96
  • 818
  • 769

1 Answers1

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?

Community
  • 1
  • 1
Northover
  • 981
  • 8
  • 14