• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Infinite for loop....???

 
Naveen Raja
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can you please tell me how the following for loop can be a infinite loop..

for(int i=0;i<=012;i=i++)
{
}

I think the whole point is increment operation on i.When exactly it happens...??

Thanks a lot
Cheers,

Naveen

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The whole point is that i=i++ is equivalent to i=i.
i gets evaluated before being incremented.

Try this :
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this one from the FAQ: Post increment operator and assignment

By the way, can you guess what this code will print?

I bet you will be surprised with the output.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic