aspose 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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: 9382
    
    2

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, Certified Scrum Master
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://aspose.com/file-tools
 
subject: What is the difference between these two loops