File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What is the difference between these two loops Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "What is the difference between these two loops" Watch "What is the difference between these two loops" New topic
Author

What is the difference between these two loops

manishsharma sharma
Greenhorn

Joined: Jun 17, 2005
Posts: 24
Hi,

can any body tell me what is the difference between these two loops

for(int i=0; i<10; i++){
System.out.println(i);
}

and

for(int i=0; i<10; ++i){
System.out.println(i);
}


Thanks


Thanks, Manish
SCJP-100, SCMAD-91, SCWCD-89, http://javatechtips.blogspot.com/
tc king
Greenhorn

Joined: Nov 10, 2006
Posts: 11
I think there is no diffirence between the two loops.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 8795

First one prints 0 to 9 and the second one prints 0 to 9.
[ November 20, 2006: Message edited by: Jothi Shankar Kumar Sankararaj ]

SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
No difference,but the jumbles starts once you these operators pre/postfix bequeaths the for loop (body).


~Sanjeev Singh<br />SCJP 1.5
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Sanjeev Kumar Singh:
No difference,but the jumbles starts once you these operators pre/postfix bequeaths the for loop (body).


Pardon?



Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
I mean the behaviour of both the operators will be same in both the case

for(int i=0; i<10; i++){
System.out.println(i);
}
and
for(int i=0; i<10; ++i){
System.out.println(i);
}

Unless you do some assignment something like
for (int i = 0,j=0; i < 12; j=i++) {
}
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: What is the difference between these two loops
 
Similar Threads
Object creation
colums Need help!!
using Iterator or without using Iterator
Performance difference between Long.longValue() and Long.parseLong()
Enhanced For Loop Problem