Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • 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: 10124
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++) {
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic