• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Performance difference between for loop and while loop in c++

 
arun david
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any performance difference between for loop and while loop in c++.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arun,

Welcome to JavaRanch!

This forum is for asking questions about Java performance issues. Similarly, all the other forums concern Java, not C++ (although the "General Computing" forum might be a place for a question like this.) If you've got more C++ questions, it'd be better to take them somewhere else besides JavaRanch.

Rather than move this thread to General Computing, though, I'll answer it just this once: No, in general, there's no difference. In fact, something like



and something like



will generally compile to identical machine code.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And to bring this thread on topic, the same is true in Java, isn't it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic