Posted By

callmeblessed on 01/02/09


Tagged

groovy grails


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

laurenceosx


looping with index


 / Published in: Groovy
 

how to loop an array / collection / list but with index. instead of using each{} closure, you can use eachWithIndex{} closure

  1. // index started with 0
  2.  
  3. def x= [1,2,3,445,6];
  4. x.eachWithIndex{ obj, index ->
  5. println("${index}. ${obj}");
  6. }

Report this snippet  

You need to login to post a comment.