• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the difference between these two loops

 
manishsharma sharma
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
tc king
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there is no diffirence between the two loops.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First one prints 0 to 9 and the second one prints 0 to 9.
[ November 20, 2006: Message edited by: Jothi Shankar Kumar Sankararaj ]
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No difference,but the jumbles starts once you these operators pre/postfix bequeaths the for loop (body).
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sanjeev Kumar Singh:
No difference,but the jumbles starts once you these operators pre/postfix bequeaths the for loop (body).


Pardon?

 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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've got no option but to sell you all for scientific experiments. Or a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!