Control Flow Statements Explained

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I understand the concept behind for and do/while loops, but I am trying to understand what is happening at the hardware level that allows a loop to run infinitely. Technically wouldn't it have to stop at some point because there are only a couple billion transistors in a microprocessor? Maybe my logic is off.










share|cite|improve this question

























    up vote
    2
    down vote

    favorite












    I understand the concept behind for and do/while loops, but I am trying to understand what is happening at the hardware level that allows a loop to run infinitely. Technically wouldn't it have to stop at some point because there are only a couple billion transistors in a microprocessor? Maybe my logic is off.










    share|cite|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I understand the concept behind for and do/while loops, but I am trying to understand what is happening at the hardware level that allows a loop to run infinitely. Technically wouldn't it have to stop at some point because there are only a couple billion transistors in a microprocessor? Maybe my logic is off.










      share|cite|improve this question













      I understand the concept behind for and do/while loops, but I am trying to understand what is happening at the hardware level that allows a loop to run infinitely. Technically wouldn't it have to stop at some point because there are only a couple billion transistors in a microprocessor? Maybe my logic is off.







      loops






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked 3 hours ago









      Cody Rutscher

      185




      185




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          step 1: take a calculator



          step 2: input a number



          step 3: add 1 to the number



          step 4: subtract 1 from the number



          step 5: goto step 3



          If you didn't eventually get tired or bored you would be switching between the 2 results forever. Computers don't get tired or bored.






          share|cite|improve this answer



























            up vote
            3
            down vote













            In a contemporary processor there is, among many other things, a register (digital electronic component to hold some bits) called the Program Counter (PC). It holds the memory address to the current machine instruction.



            During normal flow of the program, the PC will always be updated to address the next instruction. However, any loop will be implemented with so called branch or jump type instructions which will cause the PC to address some other instruction, rather than the next one.



            One, if not the, simplest infinite loop, is one in which the PC is updated again to the same instruction.



            An assembly (MIPS) code example (beq stands for Branch on Equal):



            LABEL: beq $0, $0, LABEL # Comment: If 0 == 0,then goto LABEL.





            share|cite|improve this answer










            New contributor




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

















              Your Answer





              StackExchange.ifUsing("editor", function ()
              return StackExchange.using("mathjaxEditing", function ()
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
              );
              );
              , "mathjax-editing");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "419"
              ;
              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: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              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%2fcs.stackexchange.com%2fquestions%2f99806%2fcontrol-flow-statements-explained%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              2
              down vote



              accepted










              step 1: take a calculator



              step 2: input a number



              step 3: add 1 to the number



              step 4: subtract 1 from the number



              step 5: goto step 3



              If you didn't eventually get tired or bored you would be switching between the 2 results forever. Computers don't get tired or bored.






              share|cite|improve this answer
























                up vote
                2
                down vote



                accepted










                step 1: take a calculator



                step 2: input a number



                step 3: add 1 to the number



                step 4: subtract 1 from the number



                step 5: goto step 3



                If you didn't eventually get tired or bored you would be switching between the 2 results forever. Computers don't get tired or bored.






                share|cite|improve this answer






















                  up vote
                  2
                  down vote



                  accepted







                  up vote
                  2
                  down vote



                  accepted






                  step 1: take a calculator



                  step 2: input a number



                  step 3: add 1 to the number



                  step 4: subtract 1 from the number



                  step 5: goto step 3



                  If you didn't eventually get tired or bored you would be switching between the 2 results forever. Computers don't get tired or bored.






                  share|cite|improve this answer












                  step 1: take a calculator



                  step 2: input a number



                  step 3: add 1 to the number



                  step 4: subtract 1 from the number



                  step 5: goto step 3



                  If you didn't eventually get tired or bored you would be switching between the 2 results forever. Computers don't get tired or bored.







                  share|cite|improve this answer












                  share|cite|improve this answer



                  share|cite|improve this answer










                  answered 2 hours ago









                  ratchet freak

                  2,24767




                  2,24767




















                      up vote
                      3
                      down vote













                      In a contemporary processor there is, among many other things, a register (digital electronic component to hold some bits) called the Program Counter (PC). It holds the memory address to the current machine instruction.



                      During normal flow of the program, the PC will always be updated to address the next instruction. However, any loop will be implemented with so called branch or jump type instructions which will cause the PC to address some other instruction, rather than the next one.



                      One, if not the, simplest infinite loop, is one in which the PC is updated again to the same instruction.



                      An assembly (MIPS) code example (beq stands for Branch on Equal):



                      LABEL: beq $0, $0, LABEL # Comment: If 0 == 0,then goto LABEL.





                      share|cite|improve this answer










                      New contributor




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





















                        up vote
                        3
                        down vote













                        In a contemporary processor there is, among many other things, a register (digital electronic component to hold some bits) called the Program Counter (PC). It holds the memory address to the current machine instruction.



                        During normal flow of the program, the PC will always be updated to address the next instruction. However, any loop will be implemented with so called branch or jump type instructions which will cause the PC to address some other instruction, rather than the next one.



                        One, if not the, simplest infinite loop, is one in which the PC is updated again to the same instruction.



                        An assembly (MIPS) code example (beq stands for Branch on Equal):



                        LABEL: beq $0, $0, LABEL # Comment: If 0 == 0,then goto LABEL.





                        share|cite|improve this answer










                        New contributor




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



















                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          In a contemporary processor there is, among many other things, a register (digital electronic component to hold some bits) called the Program Counter (PC). It holds the memory address to the current machine instruction.



                          During normal flow of the program, the PC will always be updated to address the next instruction. However, any loop will be implemented with so called branch or jump type instructions which will cause the PC to address some other instruction, rather than the next one.



                          One, if not the, simplest infinite loop, is one in which the PC is updated again to the same instruction.



                          An assembly (MIPS) code example (beq stands for Branch on Equal):



                          LABEL: beq $0, $0, LABEL # Comment: If 0 == 0,then goto LABEL.





                          share|cite|improve this answer










                          New contributor




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









                          In a contemporary processor there is, among many other things, a register (digital electronic component to hold some bits) called the Program Counter (PC). It holds the memory address to the current machine instruction.



                          During normal flow of the program, the PC will always be updated to address the next instruction. However, any loop will be implemented with so called branch or jump type instructions which will cause the PC to address some other instruction, rather than the next one.



                          One, if not the, simplest infinite loop, is one in which the PC is updated again to the same instruction.



                          An assembly (MIPS) code example (beq stands for Branch on Equal):



                          LABEL: beq $0, $0, LABEL # Comment: If 0 == 0,then goto LABEL.






                          share|cite|improve this answer










                          New contributor




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









                          share|cite|improve this answer



                          share|cite|improve this answer








                          edited 28 mins ago





















                          New contributor




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









                          answered 1 hour ago









                          Klorax

                          315




                          315




                          New contributor




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





                          New contributor





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






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



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f99806%2fcontrol-flow-statements-explained%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery