Difference between revisions of "Control flow"
m (link loop) |
m (link 'conditional') |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | '''Control flow''' refers to the means for controlling the order in which sections of a [[program]] are | + | '''Control flow''' refers to the means for controlling the order in which sections of a [[program]] are [[execute]]d. |
− | The underlying [[Central Processing Unit|CPU]]'s [[instruction set]] | + | The underlying [[Central Processing Unit|CPU]]'s [[instruction set]] will have a number of '''transfer of control''' primitives: [[jump]]/branch, both un-conditional as well as [[conditional branch]]es; and [[subroutine]] calls. |
− | [[Programming language]]s often add additional mechanisms, particularly '''block structures''', in which a group of instructions are treated as a unit for various control mechanisms (e.g. [[loop]]s, if-then-else constructs, etc). | + | [[Programming language]]s often add additional mechanisms, particularly '''block structures''', in which a group of instructions are treated as a unit for various control flow mechanisms (e.g. [[loop]]s, [[conditional]] if-then-else constructs, etc). |
Blocks are also often used to control the [[scope]] over which variables (particularly [[local variable]]s) are accessible. | Blocks are also often used to control the [[scope]] over which variables (particularly [[local variable]]s) are accessible. | ||
[[Interrupt]]s and [[exception]]s also divert the flow of control in a computer, but at times which are not always predictable. | [[Interrupt]]s and [[exception]]s also divert the flow of control in a computer, but at times which are not always predictable. | ||
+ | |||
+ | [[Category: Software Basics]] |
Latest revision as of 14:17, 12 May 2023
Control flow refers to the means for controlling the order in which sections of a program are executed.
The underlying CPU's instruction set will have a number of transfer of control primitives: jump/branch, both un-conditional as well as conditional branches; and subroutine calls.
Programming languages often add additional mechanisms, particularly block structures, in which a group of instructions are treated as a unit for various control flow mechanisms (e.g. loops, conditional if-then-else constructs, etc).
Blocks are also often used to control the scope over which variables (particularly local variables) are accessible.
Interrupts and exceptions also divert the flow of control in a computer, but at times which are not always predictable.