amit kumararya wrote:
I have never seen anything like this.
Please let me know what is the concept they are using and where to study that from.
Campbell Ritchie wrote:It's in the Java Tutorials; if you miss out the middle part of the header of a for loop, the compiler will assume you mean true and you get an infinite loop.
Campbell Ritchie wrote:Let's have a look in the Java Language Specification; that should confirm or refute what I said. It seems to behave like that, although the statement may terminate the loop, with break or an Exception or similar. Second • after §220.127.116.11.
It says the “statement” is executed if the “expression” evaluates to true or is absent.
Jesper de Jong wrote:If, for some reason, you must have an infinite loop in your program, then in my opinion it's much better to usewhich is much more clear than the obscure for(;;) syntax.
It would probably have been better to require all three parts of the for loop header otherwise there would be a compile‑time error. But as you say, they obviously wanted to attract C/C++ chappies, so they made the syntax appear familiar.
Winston Gutkowski wrote: . . . I really dislike syntax where the absence of something has an implied meaning . . . but 'for(;;)' is pretty widely known in C circles, so I guess they thought it might confuse people.
amit kumararya wrote:Thanks a lot steve. I got your answer when you replied. ...I haven't checked this thread since then. So i am very sorry regarding this discussion went in some other direction.
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton