A structure is a basic unit of programming logic. In computer programming, there are four basic control structures. They are Sequence, Selection, Loop and Unconditional Branch. With these structures alone, you can program any task from very complex to easy conversion of temperature.
Sequence Structure
According to Webopedia, "in a sequence structure, an action, or event, leads to the next ordered action in a predetermined order. The sequence can contain any number of actions, but no actions can be skipped in the sequence. The program, when run, must perform each action in order with no possibility of skipping an action or branching off to another action. "
The following chart depicting the Sequence Structure was obtained from: http://web.gccaz.edu/~gmarrer/cis150abbb/lessons/lesson4/lesson45.html
Selection Structure
According to Webopedia, "in a selection structure, a question is asked, and depending on the answer, the program takes one of two courses of action, after which the program moves on to the next event.
This structure is sometimes referred to as an if-then-else because it directs the program to perform in this way: If Condition A is True then perform Action X else perform Action Y. "
The following chart depicting the Selection Structure was obtained from: http://www.logiccoder.com/Tutorial/FlowchartTutorial00.htm
According to webopedia, "in a loop structure, the program asks a question, and if the answer requires an action, it is performed and the original question is asked again until the answer is such that the action is no longer required. For example, a program written to compute a company??s weekly payroll for each individual employee will begin by computing the wages of one employee and continue performing that action in a loop until there are no more employee wages to be computed, and only then will the program move on to its next action. Each pass through the loop is called an iteration. Loops constitute one of the most basic and powerful programming concepts."
The following chart depicting the Selection Structure was obtained from: http://www.google.com/images
Unconditional Branch Structure
I did not find much information on the Unconditional Branch, but this is what Wikipedia writes: “A branch (or jump on some computer architectures, ) is a point in a computer program where the flow of control is altered. The term branch is usually used when referring to a program written in machine code or assembly language; in a high-level programming language, branches usually take the form of conditional statements, subroutine calls or GOTO statements. An instruction that causes a branch, a branch instruction, can be taken or not taken: if a branch is not taken, the flow of control is unchanged and the next instruction to be executed is the instruction immediately following the current instruction in memory; if taken, the next instruction to be executed is an instruction at some other place in memory.”
The following chart depicting the Branch Structure was obtained from: http://www.google.com/images
References:
http://en.wikipedia.org/wiki/Branch_%28computer_science%29
No comments:
Post a Comment