Sunday, April 17, 2011

Basic Control Structures

Four basic control structures in modern computer programming are a Sequence, a Selection, a Loop, and a Branch.  They all provide different ways for computers to follow programming languages.  In layman’s terms, they are maps for a computer to follow when reading code.  They tell computers where to go next.  Control Statements provide instructions on which statements to execute first and what path of statements to follow depending on the conditions provided in the present Control Structures.

A.  Sequence
 - The sequence control structure is the simplest of all basic control structures.  In a sequence, statements are executed in order, one after another, as the sequence states.  It is simply a series of statements with no decision making, looping, or branching.  Sequences are like a straight line.  There can be as many statements as you would like in a sequence as long as they are executed one after the next in the order determined by the programmer that wrote the Sequence. 

B.  Selection (Decision, If Then/Else) – A Selection Control structure is a structure that provides a decision when a question is asked.  Selection is limited to a true or false / yes or no statement.  When a question proves to be true then a statement or a sequence of statements will be executed.  When a question proves to be false a different statement of sequence of statements will be executed.  The If Then/Else statement is similar.  If something is true than a certain statement or sequence will be executed, if it is false than nothing will be executed and that statement or sequence will be skipped.  The Case Control structure is presented when you need an option for more than two alternative results.  It is basically an extended form of the Selection structure.

C.  Loop (looping, iteration) – A loop is a control structure that executes statements repeatedly.  Loops contain three basic parts:  a loop termination decision (determines when the loop will terminate), the body of the loop (the statements that are repeated in the loop), and a transfer to the beginning of the loop (returns control to the top of the loop, beginning a new iteration).  The two basic types of loops are the Pre-test Loop and the Post-test Loop.  A Pre-test Loop executes the loop termination decision first.  If conditions are favorable to execute the body of the loop, those statements are executed followed by a transfer to the beginning of the loop (the loop termination decision).  A Post-test Loop executes the body of the loop first, followed by the loop termination decision.  If conditions are favorable a transfer to the beginning of the loop is executed, followed by an iteration of the body of the loop.
                                        Pre-Test Loop                                                                        Post-Test Loop
















D.  Unconditional Branch (GOTO) – A Unconditional Branch Control Structure or GOTO Statement is a simple statement.  There is no decision to be made.  Basically it instructs the computer to jump to a specified label or line of code unconditionally (no matter what).  Most high-level languages use the GOTO instruction followed by a destination to perform this operation.  Similarly, a Conditional Branch Control Structure provides the same GOTO instruction but it is based on a Boolean (true/false) condition.  If the condition is true the GOTO instruction is followed, if the condition is false it does not.  The constructs of modern programming and the Control Structures listed above virtually eliminate the need for GOTO statements.  Today, GOTO statements are mostly required when writing error-handling code.

Wednesday, April 13, 2011

Data Structures, Data Types, and Data Representation


Global Variable – a variable that can be accessed by all modules and functions at any time.  It is not confined to a single block.  Global variables are commonly kept to a minimum because the more there are bug isolation is more difficult.

Local Variable – a variable that is confined to a single block.  Local variables are only accessible from the function or block of which it is declared to. 

Elementary Data Types
•Character – a single byte of information, either a single letter, number, or symbol
•String – a contiguous set of alphanumeric data that doesn’t contain numbers
                        used for calculations
•Integer
- a whole number or natural number, not a decimal or fraction
•Floating
- a number whose decimal can be placed anywhere relative to the
significant digits of that number
•Boolean
- a yes or no, true or false

Data Identifier (name) – a name that is assigned to a field or variable that identifies your data.

Its Data Type – part of a data identifier that classifies or identifies what type of data that various data is. 

Its Memory Address – an identifier for a memory location.  It relates the exact place in a computers memory that certain data is stored.

The Actual Data – is the data that can be manipulated depending on its type.  It is what all pointers point to.

A Variable – A symbolic name given to a value that can be changed or modified.

Literal – any data that is typed by a programmer and remains unchanged when translated into machine code.  An example would be a text message displayed on the screen or a constant numerical value used for calculation purposes.

Constant – any fixed value in a program such as error messages, dates, minimum and maximum amounts, etc.

Number Base Systems – a way to represent numbers where the base is the total amount of unique symbols used to represent numbers.

BASE 2 – A number system also known as binary.  It is “based” on two “numbers” or electrical states (on and off).  It is what every computers uses to operate, internally.

BASE 10 – A number system consisting of 10 digits (0, 1, 2 , 3, 4, 5, 6, 7, 8, 9).  It is the most widely used numerical system by modern civilizations.  Also known as decimal.

BASE 16 – A number system based on 16 numbers (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and (A, B, C, D, E, F) made to represent numbers 10-15.  Also known as Hexadecimal.

Floating Point – A method for storing and calculating numbers where the significant digits are stored in a separate place as the location of the radix or decimal point.

Decimal Data Representation – An exact type of numerical data that can hold a maximum of 38 digits, with the radix in any position

Direct Addressing - A memory address pertaining to data that directly identifies the storage location without using an intermediate reference.

Relative Addressing – A memory address pertaining to data that represents some distance from the base address.

Data Types and Data Abstraction – Data abstraction allows the handling of data bits in meaningful ways and is the basic motivation behind data type.  Data abstraction is a focused representation of an item or items.

•File
- a common denominator of storage containing a collection of bytes stored as an individual entity.
•Record
- a group of related fields that store data about a subject.  A collection of records makes up a file.
•Array
- an arrangement of data elements in a particular order.  An array can hold multiple variables.
1.Single Dimension
- also known as a vector, a vector array is like a list.
2.Multi dimension
- also known as a matrix, a matrix array arranges elements in a row and column form

Language Statements – a statement is the smallest element of imperative programming languages.  Imperative programming languages use a sequence of one or  more statements to form a program.
A. Natural Language Statements/Grammar and Logic
- statements using a natural language (a human language)
B. Artificial Language Statements/Syntax and Semantics
- statements using symbols that correspond to instructions in a programming language
C. Input/Output Statements
- a statement telling the computer where the input is coming from how to compute it and where to send the output
D. Assignment Statements
- used to assign a value to a variable
E. Program Design Language (PDL) - Meta Language
- a language used to make a statement about a statement in another language.
1.Syntax Diagrams
- a diagram that explains how the syntax of a language is used, each diagram has a beginning and end point, and shows all possible paths between these two points.
2.BNF
(Backus-Naur Form)- A notation technique used to describe the syntax of a language, mostly for exact descriptions of languages, probably used in the language’s manual.
F. Elementary Language Statements and Structured Language Statement
- elementary language statements are statements in a programming language at a basic level.  Structured language statements are statements that are paired together in order to minimize error.
1.Assignment and Unconditional Statements
- Assignment and Unconditional statements are statements that produce the same result unconditionally.
2.Selection and Looping Statement
- a selection statement is a statement that chooses to perform different actions or to perform no action, depending on the data it’s given.  A looping statement will repeatedly perform an action if the statement remains true, once the statement is false the action ceases.

Expressions Components – parts of a expression which include specific values, constants, variables, operators, and functions
A.  Operators, Operands and Results
- operators specify what operation to perform.  Operands specify what data is to be manipulated.  Results are what you get when operands are manipulated by operators.
            1.Unary
- when one operand is manipulated by and operator
            2.Binary
- when two operands are manipulated by an operator
B.  Simple Types

            1.Arithmetic
- using numerical values
            2.Logical
- using mathematical logic
            3.Relational – uses a model such as a spreadsheet to relate data
C.  Result

            1.Unconditional (Not Boolean)
- any result besides true or false
            2.Conditional (Boolean)
- A result of true or false


Sources: