Regarding infinite loop, need help to understand











up vote
-2
down vote

favorite












I first searched Google for my question but did not find the answer matching it.



My question is:



for(; ;){
//some code here
}


The loop is infinite, we give a condition to match, till that loop goes on.



But when we make in infinite to do the thing, again and again, so what is the limitation of the loop? I mean where does the loop stop?



Does it crash?
Or it starts again from the place it begins?



I hope I explain my question well and easy to be understandable.










share|improve this question
























  • @afaq7, add this code example in your question ... that will make the question more clear
    – mettleap
    yesterday










  • @afaq7 E.g. for(int i = 0; true;i++){ //sth done } The compllator checkes every time if the condition given in the loop is true. If you put true there, it would go for ever (until it runs out of memory).
    – Embid123
    yesterday








  • 4




    idownvotedbecau.se/noresearch, e.g. web search for infinite loop leading to Wikipedia saying "An infinite loop (or endless loop) is a sequence of instructions in a computer program which loops endlessly", and showing example for infinite loop, running "forever". Which part of "infinite" / "endlessly" / "forever" don't you understand? "where does loop stop?" Nowhere. It never stops.
    – Andreas
    yesterday












  • Lot of intelligent and knowledgable people have already posted here. You can read this: quora.com/…
    – Pritam Banerjee
    yesterday






  • 1




    "searched Google .. but did not find the answer" Link to the three closest to answering the questions. Tell us why they failed to answer the questions you have. This would demonstrate at least, a level of research, and would certainly help others to understand better how & what to explain.
    – Andrew Thompson
    yesterday















up vote
-2
down vote

favorite












I first searched Google for my question but did not find the answer matching it.



My question is:



for(; ;){
//some code here
}


The loop is infinite, we give a condition to match, till that loop goes on.



But when we make in infinite to do the thing, again and again, so what is the limitation of the loop? I mean where does the loop stop?



Does it crash?
Or it starts again from the place it begins?



I hope I explain my question well and easy to be understandable.










share|improve this question
























  • @afaq7, add this code example in your question ... that will make the question more clear
    – mettleap
    yesterday










  • @afaq7 E.g. for(int i = 0; true;i++){ //sth done } The compllator checkes every time if the condition given in the loop is true. If you put true there, it would go for ever (until it runs out of memory).
    – Embid123
    yesterday








  • 4




    idownvotedbecau.se/noresearch, e.g. web search for infinite loop leading to Wikipedia saying "An infinite loop (or endless loop) is a sequence of instructions in a computer program which loops endlessly", and showing example for infinite loop, running "forever". Which part of "infinite" / "endlessly" / "forever" don't you understand? "where does loop stop?" Nowhere. It never stops.
    – Andreas
    yesterday












  • Lot of intelligent and knowledgable people have already posted here. You can read this: quora.com/…
    – Pritam Banerjee
    yesterday






  • 1




    "searched Google .. but did not find the answer" Link to the three closest to answering the questions. Tell us why they failed to answer the questions you have. This would demonstrate at least, a level of research, and would certainly help others to understand better how & what to explain.
    – Andrew Thompson
    yesterday













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











I first searched Google for my question but did not find the answer matching it.



My question is:



for(; ;){
//some code here
}


The loop is infinite, we give a condition to match, till that loop goes on.



But when we make in infinite to do the thing, again and again, so what is the limitation of the loop? I mean where does the loop stop?



Does it crash?
Or it starts again from the place it begins?



I hope I explain my question well and easy to be understandable.










share|improve this question















I first searched Google for my question but did not find the answer matching it.



My question is:



for(; ;){
//some code here
}


The loop is infinite, we give a condition to match, till that loop goes on.



But when we make in infinite to do the thing, again and again, so what is the limitation of the loop? I mean where does the loop stop?



Does it crash?
Or it starts again from the place it begins?



I hope I explain my question well and easy to be understandable.







java loops infinite-loop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









Andrew Thompson

152k27159333




152k27159333










asked yesterday









afaq7

126




126












  • @afaq7, add this code example in your question ... that will make the question more clear
    – mettleap
    yesterday










  • @afaq7 E.g. for(int i = 0; true;i++){ //sth done } The compllator checkes every time if the condition given in the loop is true. If you put true there, it would go for ever (until it runs out of memory).
    – Embid123
    yesterday








  • 4




    idownvotedbecau.se/noresearch, e.g. web search for infinite loop leading to Wikipedia saying "An infinite loop (or endless loop) is a sequence of instructions in a computer program which loops endlessly", and showing example for infinite loop, running "forever". Which part of "infinite" / "endlessly" / "forever" don't you understand? "where does loop stop?" Nowhere. It never stops.
    – Andreas
    yesterday












  • Lot of intelligent and knowledgable people have already posted here. You can read this: quora.com/…
    – Pritam Banerjee
    yesterday






  • 1




    "searched Google .. but did not find the answer" Link to the three closest to answering the questions. Tell us why they failed to answer the questions you have. This would demonstrate at least, a level of research, and would certainly help others to understand better how & what to explain.
    – Andrew Thompson
    yesterday


















  • @afaq7, add this code example in your question ... that will make the question more clear
    – mettleap
    yesterday










  • @afaq7 E.g. for(int i = 0; true;i++){ //sth done } The compllator checkes every time if the condition given in the loop is true. If you put true there, it would go for ever (until it runs out of memory).
    – Embid123
    yesterday








  • 4




    idownvotedbecau.se/noresearch, e.g. web search for infinite loop leading to Wikipedia saying "An infinite loop (or endless loop) is a sequence of instructions in a computer program which loops endlessly", and showing example for infinite loop, running "forever". Which part of "infinite" / "endlessly" / "forever" don't you understand? "where does loop stop?" Nowhere. It never stops.
    – Andreas
    yesterday












  • Lot of intelligent and knowledgable people have already posted here. You can read this: quora.com/…
    – Pritam Banerjee
    yesterday






  • 1




    "searched Google .. but did not find the answer" Link to the three closest to answering the questions. Tell us why they failed to answer the questions you have. This would demonstrate at least, a level of research, and would certainly help others to understand better how & what to explain.
    – Andrew Thompson
    yesterday
















@afaq7, add this code example in your question ... that will make the question more clear
– mettleap
yesterday




@afaq7, add this code example in your question ... that will make the question more clear
– mettleap
yesterday












@afaq7 E.g. for(int i = 0; true;i++){ //sth done } The compllator checkes every time if the condition given in the loop is true. If you put true there, it would go for ever (until it runs out of memory).
– Embid123
yesterday






@afaq7 E.g. for(int i = 0; true;i++){ //sth done } The compllator checkes every time if the condition given in the loop is true. If you put true there, it would go for ever (until it runs out of memory).
– Embid123
yesterday






4




4




idownvotedbecau.se/noresearch, e.g. web search for infinite loop leading to Wikipedia saying "An infinite loop (or endless loop) is a sequence of instructions in a computer program which loops endlessly", and showing example for infinite loop, running "forever". Which part of "infinite" / "endlessly" / "forever" don't you understand? "where does loop stop?" Nowhere. It never stops.
– Andreas
yesterday






idownvotedbecau.se/noresearch, e.g. web search for infinite loop leading to Wikipedia saying "An infinite loop (or endless loop) is a sequence of instructions in a computer program which loops endlessly", and showing example for infinite loop, running "forever". Which part of "infinite" / "endlessly" / "forever" don't you understand? "where does loop stop?" Nowhere. It never stops.
– Andreas
yesterday














Lot of intelligent and knowledgable people have already posted here. You can read this: quora.com/…
– Pritam Banerjee
yesterday




Lot of intelligent and knowledgable people have already posted here. You can read this: quora.com/…
– Pritam Banerjee
yesterday




1




1




"searched Google .. but did not find the answer" Link to the three closest to answering the questions. Tell us why they failed to answer the questions you have. This would demonstrate at least, a level of research, and would certainly help others to understand better how & what to explain.
– Andrew Thompson
yesterday




"searched Google .. but did not find the answer" Link to the three closest to answering the questions. Tell us why they failed to answer the questions you have. This would demonstrate at least, a level of research, and would certainly help others to understand better how & what to explain.
– Andrew Thompson
yesterday












5 Answers
5






active

oldest

votes

















up vote
1
down vote













If I understood correctly, you mean to make a sort of:



while(true){/*here be code*/}  


then unless you don't tell it to stop, it won't. Unless you are doing something wrong inside the loop it will not crash, it will simply do the things you specify again and again until you tell it to stop. you can do this by either placing a break;, something stops your program or making the while's parameter a variable that can be changed inside the code eg:



int i=0;
while(i != 1){
if(?){
i++;
}
?
}


But yea, otherwise the loop will keep well, looping.






share|improve this answer








New contributor




Alejo Niss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    0
    down vote













    Consider the following infinite loop in which the condition is omitted:



     for(int i=1;;i++){
    System.out.println(i);
    }


    Yes, the loop will continue unless interrupted (ctrl+ c) or your laptop's battery die out!
    Output:
    1
    2
    3
    .
    .
    Running the loop again will begin for the initialization i.e. 1



    You may want to read up the concepts of memory (Stack overflow!) to understand how it will not go on forever in practice.






    share|improve this answer




























      up vote
      0
      down vote













      An infinity loop will keep on going until you stop it, or your computer dies.
      You need to make sure your loop stops at somepoint, like when you reach the end of an arraylist.






      share|improve this answer








      New contributor




      Skou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

























        up vote
        -1
        down vote













        Do you mean when the loop is infinite?
        There's many ways to make an infinite loop. But if you realy want to do so I guess by convention it's not recommended because the program will run until it run out of memory.
        Let's take as exemple the code bellow that will print how many times you want to show something happening but you forgot to put an incrementer so you made an infinite loop that will run over and over until your machine could not handle anymore.



        int count = 0;

        while(count <= 42) {
        System.out.print(count + " Times running your program");
        }


        I'm sorry if you got you wrong.






        share|improve this answer





















        • Your example should never "run out of memory" ... because nothing in the loop ever allocates more memory. The laptop it's executing on might run out of battery. But it shouldn't run out of memory. ALSO: One thing that nobody's mentioned is that an "infinite loop" ISN'T NECESSARILY BAD. One example is an application's "main event loop": something at the heart of most every Windows, Mac and Linux GUI program. It loops forever - processing UI events. Until it receives an "Exit" event. Which instructs the app to terminate itself (often with an "exit()" system call)..
          – paulsm4
          yesterday




















        up vote
        -2
        down vote













        Below is a simple infinite loop :



        while(true) ;



        The above loop does nothing, it will just keep going on.
        In the loop we are not using any variable or object so memory consumption is bare minimum.
        I think it will go on until somehow JVM gets terminated intentionally/unintentionally or it runs out of memory/memory related error or when the main thread gets terminated.






        share|improve this answer





















          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343499%2fregarding-infinite-loop-need-help-to-understand%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          If I understood correctly, you mean to make a sort of:



          while(true){/*here be code*/}  


          then unless you don't tell it to stop, it won't. Unless you are doing something wrong inside the loop it will not crash, it will simply do the things you specify again and again until you tell it to stop. you can do this by either placing a break;, something stops your program or making the while's parameter a variable that can be changed inside the code eg:



          int i=0;
          while(i != 1){
          if(?){
          i++;
          }
          ?
          }


          But yea, otherwise the loop will keep well, looping.






          share|improve this answer








          New contributor




          Alejo Niss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






















            up vote
            1
            down vote













            If I understood correctly, you mean to make a sort of:



            while(true){/*here be code*/}  


            then unless you don't tell it to stop, it won't. Unless you are doing something wrong inside the loop it will not crash, it will simply do the things you specify again and again until you tell it to stop. you can do this by either placing a break;, something stops your program or making the while's parameter a variable that can be changed inside the code eg:



            int i=0;
            while(i != 1){
            if(?){
            i++;
            }
            ?
            }


            But yea, otherwise the loop will keep well, looping.






            share|improve this answer








            New contributor




            Alejo Niss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.




















              up vote
              1
              down vote










              up vote
              1
              down vote









              If I understood correctly, you mean to make a sort of:



              while(true){/*here be code*/}  


              then unless you don't tell it to stop, it won't. Unless you are doing something wrong inside the loop it will not crash, it will simply do the things you specify again and again until you tell it to stop. you can do this by either placing a break;, something stops your program or making the while's parameter a variable that can be changed inside the code eg:



              int i=0;
              while(i != 1){
              if(?){
              i++;
              }
              ?
              }


              But yea, otherwise the loop will keep well, looping.






              share|improve this answer








              New contributor




              Alejo Niss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              If I understood correctly, you mean to make a sort of:



              while(true){/*here be code*/}  


              then unless you don't tell it to stop, it won't. Unless you are doing something wrong inside the loop it will not crash, it will simply do the things you specify again and again until you tell it to stop. you can do this by either placing a break;, something stops your program or making the while's parameter a variable that can be changed inside the code eg:



              int i=0;
              while(i != 1){
              if(?){
              i++;
              }
              ?
              }


              But yea, otherwise the loop will keep well, looping.







              share|improve this answer








              New contributor




              Alejo Niss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              share|improve this answer



              share|improve this answer






              New contributor




              Alejo Niss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.









              answered yesterday









              Alejo Niss

              113




              113




              New contributor




              Alejo Niss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





              New contributor





              Alejo Niss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              Alejo Niss is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.
























                  up vote
                  0
                  down vote













                  Consider the following infinite loop in which the condition is omitted:



                   for(int i=1;;i++){
                  System.out.println(i);
                  }


                  Yes, the loop will continue unless interrupted (ctrl+ c) or your laptop's battery die out!
                  Output:
                  1
                  2
                  3
                  .
                  .
                  Running the loop again will begin for the initialization i.e. 1



                  You may want to read up the concepts of memory (Stack overflow!) to understand how it will not go on forever in practice.






                  share|improve this answer

























                    up vote
                    0
                    down vote













                    Consider the following infinite loop in which the condition is omitted:



                     for(int i=1;;i++){
                    System.out.println(i);
                    }


                    Yes, the loop will continue unless interrupted (ctrl+ c) or your laptop's battery die out!
                    Output:
                    1
                    2
                    3
                    .
                    .
                    Running the loop again will begin for the initialization i.e. 1



                    You may want to read up the concepts of memory (Stack overflow!) to understand how it will not go on forever in practice.






                    share|improve this answer























                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      Consider the following infinite loop in which the condition is omitted:



                       for(int i=1;;i++){
                      System.out.println(i);
                      }


                      Yes, the loop will continue unless interrupted (ctrl+ c) or your laptop's battery die out!
                      Output:
                      1
                      2
                      3
                      .
                      .
                      Running the loop again will begin for the initialization i.e. 1



                      You may want to read up the concepts of memory (Stack overflow!) to understand how it will not go on forever in practice.






                      share|improve this answer












                      Consider the following infinite loop in which the condition is omitted:



                       for(int i=1;;i++){
                      System.out.println(i);
                      }


                      Yes, the loop will continue unless interrupted (ctrl+ c) or your laptop's battery die out!
                      Output:
                      1
                      2
                      3
                      .
                      .
                      Running the loop again will begin for the initialization i.e. 1



                      You may want to read up the concepts of memory (Stack overflow!) to understand how it will not go on forever in practice.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered yesterday









                      Chica_Programmador

                      23110




                      23110






















                          up vote
                          0
                          down vote













                          An infinity loop will keep on going until you stop it, or your computer dies.
                          You need to make sure your loop stops at somepoint, like when you reach the end of an arraylist.






                          share|improve this answer








                          New contributor




                          Skou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






















                            up vote
                            0
                            down vote













                            An infinity loop will keep on going until you stop it, or your computer dies.
                            You need to make sure your loop stops at somepoint, like when you reach the end of an arraylist.






                            share|improve this answer








                            New contributor




                            Skou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.




















                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              An infinity loop will keep on going until you stop it, or your computer dies.
                              You need to make sure your loop stops at somepoint, like when you reach the end of an arraylist.






                              share|improve this answer








                              New contributor




                              Skou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.









                              An infinity loop will keep on going until you stop it, or your computer dies.
                              You need to make sure your loop stops at somepoint, like when you reach the end of an arraylist.







                              share|improve this answer








                              New contributor




                              Skou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.









                              share|improve this answer



                              share|improve this answer






                              New contributor




                              Skou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.









                              answered yesterday









                              Skou

                              12




                              12




                              New contributor




                              Skou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.





                              New contributor





                              Skou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.






                              Skou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                              Check out our Code of Conduct.






















                                  up vote
                                  -1
                                  down vote













                                  Do you mean when the loop is infinite?
                                  There's many ways to make an infinite loop. But if you realy want to do so I guess by convention it's not recommended because the program will run until it run out of memory.
                                  Let's take as exemple the code bellow that will print how many times you want to show something happening but you forgot to put an incrementer so you made an infinite loop that will run over and over until your machine could not handle anymore.



                                  int count = 0;

                                  while(count <= 42) {
                                  System.out.print(count + " Times running your program");
                                  }


                                  I'm sorry if you got you wrong.






                                  share|improve this answer





















                                  • Your example should never "run out of memory" ... because nothing in the loop ever allocates more memory. The laptop it's executing on might run out of battery. But it shouldn't run out of memory. ALSO: One thing that nobody's mentioned is that an "infinite loop" ISN'T NECESSARILY BAD. One example is an application's "main event loop": something at the heart of most every Windows, Mac and Linux GUI program. It loops forever - processing UI events. Until it receives an "Exit" event. Which instructs the app to terminate itself (often with an "exit()" system call)..
                                    – paulsm4
                                    yesterday

















                                  up vote
                                  -1
                                  down vote













                                  Do you mean when the loop is infinite?
                                  There's many ways to make an infinite loop. But if you realy want to do so I guess by convention it's not recommended because the program will run until it run out of memory.
                                  Let's take as exemple the code bellow that will print how many times you want to show something happening but you forgot to put an incrementer so you made an infinite loop that will run over and over until your machine could not handle anymore.



                                  int count = 0;

                                  while(count <= 42) {
                                  System.out.print(count + " Times running your program");
                                  }


                                  I'm sorry if you got you wrong.






                                  share|improve this answer





















                                  • Your example should never "run out of memory" ... because nothing in the loop ever allocates more memory. The laptop it's executing on might run out of battery. But it shouldn't run out of memory. ALSO: One thing that nobody's mentioned is that an "infinite loop" ISN'T NECESSARILY BAD. One example is an application's "main event loop": something at the heart of most every Windows, Mac and Linux GUI program. It loops forever - processing UI events. Until it receives an "Exit" event. Which instructs the app to terminate itself (often with an "exit()" system call)..
                                    – paulsm4
                                    yesterday















                                  up vote
                                  -1
                                  down vote










                                  up vote
                                  -1
                                  down vote









                                  Do you mean when the loop is infinite?
                                  There's many ways to make an infinite loop. But if you realy want to do so I guess by convention it's not recommended because the program will run until it run out of memory.
                                  Let's take as exemple the code bellow that will print how many times you want to show something happening but you forgot to put an incrementer so you made an infinite loop that will run over and over until your machine could not handle anymore.



                                  int count = 0;

                                  while(count <= 42) {
                                  System.out.print(count + " Times running your program");
                                  }


                                  I'm sorry if you got you wrong.






                                  share|improve this answer












                                  Do you mean when the loop is infinite?
                                  There's many ways to make an infinite loop. But if you realy want to do so I guess by convention it's not recommended because the program will run until it run out of memory.
                                  Let's take as exemple the code bellow that will print how many times you want to show something happening but you forgot to put an incrementer so you made an infinite loop that will run over and over until your machine could not handle anymore.



                                  int count = 0;

                                  while(count <= 42) {
                                  System.out.print(count + " Times running your program");
                                  }


                                  I'm sorry if you got you wrong.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered yesterday









                                  TBrito1

                                  13




                                  13












                                  • Your example should never "run out of memory" ... because nothing in the loop ever allocates more memory. The laptop it's executing on might run out of battery. But it shouldn't run out of memory. ALSO: One thing that nobody's mentioned is that an "infinite loop" ISN'T NECESSARILY BAD. One example is an application's "main event loop": something at the heart of most every Windows, Mac and Linux GUI program. It loops forever - processing UI events. Until it receives an "Exit" event. Which instructs the app to terminate itself (often with an "exit()" system call)..
                                    – paulsm4
                                    yesterday




















                                  • Your example should never "run out of memory" ... because nothing in the loop ever allocates more memory. The laptop it's executing on might run out of battery. But it shouldn't run out of memory. ALSO: One thing that nobody's mentioned is that an "infinite loop" ISN'T NECESSARILY BAD. One example is an application's "main event loop": something at the heart of most every Windows, Mac and Linux GUI program. It loops forever - processing UI events. Until it receives an "Exit" event. Which instructs the app to terminate itself (often with an "exit()" system call)..
                                    – paulsm4
                                    yesterday


















                                  Your example should never "run out of memory" ... because nothing in the loop ever allocates more memory. The laptop it's executing on might run out of battery. But it shouldn't run out of memory. ALSO: One thing that nobody's mentioned is that an "infinite loop" ISN'T NECESSARILY BAD. One example is an application's "main event loop": something at the heart of most every Windows, Mac and Linux GUI program. It loops forever - processing UI events. Until it receives an "Exit" event. Which instructs the app to terminate itself (often with an "exit()" system call)..
                                  – paulsm4
                                  yesterday






                                  Your example should never "run out of memory" ... because nothing in the loop ever allocates more memory. The laptop it's executing on might run out of battery. But it shouldn't run out of memory. ALSO: One thing that nobody's mentioned is that an "infinite loop" ISN'T NECESSARILY BAD. One example is an application's "main event loop": something at the heart of most every Windows, Mac and Linux GUI program. It loops forever - processing UI events. Until it receives an "Exit" event. Which instructs the app to terminate itself (often with an "exit()" system call)..
                                  – paulsm4
                                  yesterday












                                  up vote
                                  -2
                                  down vote













                                  Below is a simple infinite loop :



                                  while(true) ;



                                  The above loop does nothing, it will just keep going on.
                                  In the loop we are not using any variable or object so memory consumption is bare minimum.
                                  I think it will go on until somehow JVM gets terminated intentionally/unintentionally or it runs out of memory/memory related error or when the main thread gets terminated.






                                  share|improve this answer

























                                    up vote
                                    -2
                                    down vote













                                    Below is a simple infinite loop :



                                    while(true) ;



                                    The above loop does nothing, it will just keep going on.
                                    In the loop we are not using any variable or object so memory consumption is bare minimum.
                                    I think it will go on until somehow JVM gets terminated intentionally/unintentionally or it runs out of memory/memory related error or when the main thread gets terminated.






                                    share|improve this answer























                                      up vote
                                      -2
                                      down vote










                                      up vote
                                      -2
                                      down vote









                                      Below is a simple infinite loop :



                                      while(true) ;



                                      The above loop does nothing, it will just keep going on.
                                      In the loop we are not using any variable or object so memory consumption is bare minimum.
                                      I think it will go on until somehow JVM gets terminated intentionally/unintentionally or it runs out of memory/memory related error or when the main thread gets terminated.






                                      share|improve this answer












                                      Below is a simple infinite loop :



                                      while(true) ;



                                      The above loop does nothing, it will just keep going on.
                                      In the loop we are not using any variable or object so memory consumption is bare minimum.
                                      I think it will go on until somehow JVM gets terminated intentionally/unintentionally or it runs out of memory/memory related error or when the main thread gets terminated.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered yesterday









                                      Nitesh Patil

                                      12




                                      12






























                                           

                                          draft saved


                                          draft discarded



















































                                           


                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343499%2fregarding-infinite-loop-need-help-to-understand%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                                          Alcedinidae

                                          Can an atomic nucleus contain both particles and antiparticles? [duplicate]