procedural+programming+structures

=3.2.2 a=
 * ===define and correctly use the following terms as they apply to procedural programming: statement, subroutine, procedure, function, parameter/argument, sequence, selection, iteration/repetition, loop;===
 * ** Keywords ** || ** Definitions ** ||
 * ** Statement ** || A statement is a single instruction or step within a program. ||
 * ** Subroutine ** || A subroutine is a set of instructions that perform a specific task as part of a larger program The main program will contain instructions to call the subroutine. ||
 * ** Procedure ** || A procedure is a subroutine that simply executes its statements and returns control to the main program. It is usually known as an instruction to all computers. ||
 * ** Function ** || A function is a subroutine that executes its statements and returns a single value. It is usually known as part of an expression and the value returned can place the function call in the expression. ||
 * ** Parameter/ Argument ** || A parameter is an item of data that is given to a procedure or function. This is usually written and seen in the form of the brackets after the name of the procedure or function ||
 * ** Sequence ** || A sequence is a control structure in which a set of statements is each executed once, in the order they are written. ||
 * ** Selection ** || A selection is a control structure in which an option of statements is provided and a condition is used to decide which, if any, statements should be executed. ||
 * ** Iteration/ Repetition ** || An iteration/repetition is a control structure in which a group of statements is executed repeatedly. ||
 * ** Loop ** || A loop is also known as the Iteration and repetition. ||

**Sequence**
//BEGIN// //INPUT number A// //INPUT number B// //LET Total = A + B// //LET Average = Total / 2// //OUTPUT Average// //END//

This is an example of a sequence. In order to execute this program, the computer needs to start from the beginning, and excute each statement once until it gets to the end and stops.

**Selection**
This allows the programmer to select the statements which will be executed depending on a condition. The way this achieves varies in many different languages but usually through a variation of the IF Statements and the CASE Statement.

If Statement
Items in the angled brackets need to be replaced as needed by the program. The ... just means that there may be more than one instruction: //IF THEN// // // //...// //END IF//

This is a common format for an IF Statement.

CASE Statement
This uses a variable instead of a condition to determine which instructions will be executed:

//SELECT CASE OF// //CASE :// //// //CASE :// //// //CASE :// //// //...// //END SELECT//

The CASE Statement can be a useful replacement for a series of IF Statements whose conditions depend on the same variable.

**Iteration**
This is useful because we would otherwise have to write the instructions out the correct number of times.

Condition-controlled loops
This determines whether or not the instructions need to be executed. One kind of condition-controlled loop is the WHILE loop:

//WHILE // // // //...// //END WHILE//

When this code is executed, the condition is tested first. If this condition is true, then the instructions in the loop are executed. The computer goes back and tests it again. This is repeated as long as every time the condition is tested, it is true. However, if the condition is false, then the loop ends, and the control transfers to the next line after the loop.

Parameters
Sometimes a procedure needs some data to carry out its instructions. //PROCEDURE // // // //...// //END PROCEDURE//

When the procedure us called the actual values of these variables need to be supplied. These actual values are also known as arguments.

Functions
The function returns a single value to the main program that called it. //FUNCTION // // // //...// //END FUNCTION//

The instructions in a function will need to include an instruction to set the return value. This is usually done using the name of the function as a variable or by using a keyword such as "RETURN".


 * Exam Question: **