Header Ads

  • Breaking Now

    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 (;;) { }

    2 comments:

    1. for(;;);
      while(true);
      do{}while (true);

      ReplyDelete
    2. 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.

      ReplyDelete

    Post Top Ad

    Post Bottom Ad