Control Flow Statements Explained
Clash 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.
loops
add a comment |
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.
loops
add a comment |
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.
loops
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
loops
asked 3 hours ago


Cody Rutscher
185
185
add a comment |
add a comment |
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.
add a comment |
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.
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 2 hours ago
ratchet freak
2,24767
2,24767
add a comment |
add a comment |
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.
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.
add a comment |
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.
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.
add a comment |
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.
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.
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.
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.
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password