• Post Reply Bookmark Topic Watch Topic
  • New Topic

loops

 
jandost khoso
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which loop has more efficiency: while loop or for loop? and why?
plz help me.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This forum is for discussion of the JavaRanch site. We have forums that cover other discussions. This would be most appropriate in the Performance forum. I'm going to move it there.
 
Peter Haggar
author
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no difference between the two. Both of these methods compile into the same bytecode:

The bytecode they produce is:

If you are able to write 2 loops that are logically identical but that generate different bytecode (this is probably easy), I would imagine that the performance between the two would not be noticable at all.
Peter Haggar
------------------
Senior Software Engineer, IBM
author of: Practical Java
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!