Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

For each loop

 
Roel De Nijs
Sheriff
Posts: 9117
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Question Java Tiger)



concern the code in bold: i guess the method values() is executed once (at the beginning of the loop) and not every time a new value is assigned to variable kolom, because that would be a performance problem
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Values is only called once (in order to get at an Iterator).
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The values() method returns a Collection, and to iterate through that collection an Iterator is obtained from kolommen.values().iterator(). That's done only once, exactly as in the first part of a normal for loop:
 
Roel De Nijs
Sheriff
Posts: 9117
75
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Gaunt:
The values() method returns a Collection, and to iterate through that collection an Iterator is obtained from kolommen.values().iterator(). That's done only once, exactly as in the first part of a normal for loop:


that's exactly what my .class file looks like after i decompiled it (i thought too late about that option to verify my ideas (it's almost weekend so the brain is slowing down )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic