Following the structured program theorem, all programs are seen as composed of control structures:
Sequence:
Ordered statements or subroutines executed in sequence.
Selection:
One or a number of statements is executed depending on the state of the program. This is usually expressed with keywords such as if..then..else..endif.
Iteration:
A statement or block is executed until the program reaches a certain state, or operations have been applied to every element of a collection. This is usually expressed with keywords such as while, repeat, for or do...until. Often it is recommended that each loop should only have one entry point (and in the original structural programming, also only one exit point and a few language enforce this).
Recursion:
A statement is executed by repeatedly calling itself until termination conditions are met. While similar in practice to iterative loops, recursive loops may be more computationally efficient and are implemented differently as a cascading stack.
Subroutines
Subroutines; callable units such as procedures, functions, methods or subprograms are used to allow a sequence to be referred to by a single statement.
Blocks
Blocks are used to enable groups of statements to be treated as if they were one statement. Block -structured languages have a syntax for enclosing structures in some formal way, such as an if-statement bracketed by if..fi as in ALGOL 68 or a code section bracketed by BEGIN..END, as in PL/I, white space indentation as in python or the curly braces {...} of C and many later languages.
Structured Programming Languages
It is possible to do structured programming in any programming language, though it is possible preferable to use something like a procedural programming language. Some of the languages initially used for structured programming include: ALGOL, Pascal, PL/I and Ada - but most new procedural programming languages since that time have included features to encourage structured programming and sometimes deliberately left out features - notably GOTO - in an effort to make unstructured programming more difficult.
Object Oriented Vs Structured Programming
Although there are differences between structured programming and object oriented programming, they are both useful to programmers.
. Structured programming takes on the top-to-bottom approach.
. Structured programming is based around data structures and subroutines.
. It splits the tasks into modular forms. This makes the program simpler and easier to read with less lines and codes.
Object Oriented Programming
. This type of programming uses sections in a program to perform certain tasks.
. They are small programs that can be used in other softwares.
. It splits the program into objects that can be reused into other programs.
No comments:
Post a Comment