Wednesday, April 18, 2007

How many ways can one write an infinite loop ?

Personally I would recommend following ways to implement infinite loop in Java but their can be other ways like calling a method recursively , though I never tested that.

- while (true)

- for (;;) { }


TheMalkolm on September 17, 2009 at 11:36 PM said...

do{}while (true);

Anonymous said...

Calling a method recursively would not be a good idea for an infinite loop - every recursive call results in adding to the stack, and after a few times through the "loop" there would be a stack overflow.


Interview Questions On Java,Java EE Copyright © 2017. Reads: best tracker