File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Infinite for loop....??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Infinite for loop....???" Watch "Infinite for loop....???" New topic
Author

Infinite for loop....???

Naveen Raja
Greenhorn

Joined: Jul 28, 2006
Posts: 10
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

The whole point is that i=i++ is equivalent to i=i.
i gets evaluated before being incremented.

Try this :


[My Blog]
All roads lead to JavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14104
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Infinite for loop....???