Beruflich Dokumente
Kultur Dokumente
Sequence
A control structure where all statements are executed once all in order
Iteration
A control structure in which a group of statements are executed several times
depending on a condition or the number of times it is repeated can be set at the
start of the program. There are three types of iterations; FOR loop, REPEAT UNTIL
loop and WHILE loop.
FOR loop
REPEAT UNTIL
loop
WHILE loop
FOR Loop
WHILE DO loop
This is an example of a WHILE DO loop. This program will start off from a=10.
The program will only run while the value is under 20. This program keeps
repeating until the value of A becomes 20.
Selection
A control structure in which an option to execute sets of statements and a
condition is used to determine which if (any) structure will be executed. There
are two types of selection structures: IF then ELSE and a CASE structure.
IFTHENELSE
CASE
This is an example of CASE in use. Using this control structure allows different
outcomes for different inputs. In this example, the line that is outputted will
depend on the student grade that is inputted. So if A is inputted, then the
program will output Excellent work! However if E is inputted, then the
program will output Trouble ahead!
Using variables
Variables can be used to represent a value. For example x+y is an expression
and x and y are variables. X and y can represent a numerical value, characters,
character strings or memory addresses.
Subroutines
A subroutine is a portion of code within a larger program that performs a specific
task and is relatively independent of the remaining code. It is often coded so that
it can be started (called) several times during the execution of the program. It
will perform that tasks that it is assigned to. Once it has completed its tasks, it
will continue executing the instructions that come after the subroutine. There are
two types of subroutines; PROCEDURE and FUNCTION
Procedures
A procedure is a subroutine that executes its statements when it is called and it
is called when it is said.
Functions
A function is a subroutine that returns a single value to the program where it is
called.
This function is being used to compare two numbers and see which one is higher.
If A is bigger than B, then the function will return value A.
Recursion
Recursion is when a function calls on itself.
This is a function called factorial. Inside the function on line 5, you can see it
call factorial again. This is the function calling on itself. The factorial here is
multiplying (n-1) out the bracket.