File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Infinite for loop....???

Naveen Raja

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


Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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: 15081

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 8 API documentation
I agree. Here's the link:
subject: Infinite for loop....???
It's not a secret anymore!