| 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++) { }
|
 |
 |
|
|
subject: What is the difference between these two loops
|
|
|