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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 9243
    
    1

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++) {
}
 
jQuery in Action, 2nd edition
 
subject: What is the difference between these two loops
 
Similar Threads
Object creation
colums Need help!!
Enhanced For Loop Problem
Performance difference between Long.longValue() and Long.parseLong()
using Iterator or without using Iterator