logo       

Return from the Closure: msg#00089

lang.groovy.user

Subject: Return from the Closure

the code:

class test {
lt = ['a','b','c']
find1(value){
lt.each ({
if (it == value){
return "1:${it}"
}
})
return '1:not found!'
}

find2(value){
for (item in lt){
if (item == value){
return "2:${item}"
}
}
return '2:not found!'
}

static void main(argv){
ins = new test()
println ins.find1('a')
println ins.find2('a')
}
}

result:

1:not found!
2:a

I find when to be return from the Closure, it actually break the loop,
and can't return from the method. I think this not like usual habit,
please provide the opinion

thanks.

<renlixin-Re5JQEeQqe8AvxtiuMwx3w@xxxxxxxxxxxxxxxx>



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise