Notes Part 2 Essay

Submitted By yit43
Words: 2503
Pages: 11

Notes part 2- programming constructs
Iteration – repeating stuff (for loops, while loops, do while)
Control structure in which a group of statements is executed repeatedly-also called a loop or repetition
A condition determines whether or not the instructions need to be executed.
REPEAT
<Instructions to be repeated>
Until <condition>
A while loop-the condition tested before each cycle, the repeat until loop condition is tested after each cycle.
In a while loop, the instructions may never be executed if it starts out as false.
In a while loop, it repeats if the condition is true and exits if it’s false. In a repeat until loop, it repeats if the condition is false, and exits if it’s false.
A count determines whether or not the instructions need to be executed
FOR <variable> = <starting value> TO <end value>
<Instructions to be executed>
NEXT

Selection – (if, case)
Control structure in which an option of statements is provided and a condition is used to decide which statement should be executed
A case statement can be useful to replace a series of IF statements whose conditions depend on the same variable
A case statement uses a variable instead of a condition to determine which instruction should be executed
Sequence – something following after enough
Control structure in which a set of instructions is each executed once in the order they are written

A condition determines whether or not the instructions need to be executed.
REPEAT
<Instructions to be repeated>
Until <condition>
A while loop-the condition tested before each cycle, the repeat until loop condition is tested after each cycle.
In a while loop, the instructions may never be executed if it starts out as false.
In a while loop, it repeats if the condition is true and exits if it’s false. In a repeat until loop, it repeats if the condition is false, and exits if it’s false.

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;
Statement – single instruction or step within a program
Subroutine- a set of instructions that perform a specific task as part of a larger program
Procedure – a subroutine that executes its statements
Function – a subroutine that executes its statements and returns a single value
Parameter – an item of data that is given to a procedure or function
Sequence – a set of instructions are executed once, in the order they are written
Selection – options of statements are provided and a condition decides which statements should be executed
Iteration – a group of statements are executed repeatedly

f. understand, create and use subroutines (procedures and functions), including the passing of parameters and the appropriate use of the return value of functions
Advantages of subroutines: can call the same code many times without making the program longer can use subroutines to make the main program easier to understand and maintain can test the subroutine to make sure it works then reuse it with confidence only need to modify code in one place
When subroutine is defined it is given an identifier and some instructions
The identifier is the name of the subroutine which is used to call the subroutine.
2 types of subroutine:
Functions and procedures
PROCEDURE < identifier> <Instructions>
END PROCEDURE main program calls this procedure control is passed to the subroutine until all instructions are executed control is passed back to the main program, which carries on where it left off

PROCEDURE < identifier> (<parameters>) <Instructions>
END PROCEDURE a parameter may need some date to carry out its instructions variables are added in brackets after the identifier (Called parameters) when the procedure is called the actual values of these variables need to be supplied
FUNCTION higher (a,b) FUNCTION higher (a,b)
IF a > b THEN if a > b THEN
Higher = a RETURN a
ELSE…