Program constructs

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Selection

A condition is used to determine whether or not sections of code will be executed. E.g. IF....THEN....(ELSEIF...)ENDIF / SELECT CASE

Parameter

A description of an item of data supplied to a subroutine. It is given an actual value/address when the subroutine is called. It is used as a variable within subroutine.

Procedure

A named section of code which performs a task. Can be called from parent program and returns control to parent program when complete. Used as a statement in the main program. Can be sent parameters.

Function

A named section of code. It is called as part of an expression e.g. Num = LENGTH(Name) which returns a single value when called. The value replaces the function call.

Statement

A single instruction within the algorithm (which can be executed), e.g. Input X.

OUTPUT

Output tells the program to display a value on the user interface.

Recursion

When a subroutine calls itself with different parameter(s) until a stopping condition is met, (when it 'unwinds').

Keyword

Word which is already used for a purpose within the language. Reserved word/cannot be used as an identifier.

Disadvantages of iteration

Algorithm may be more difficult to follow/trace because variables are being reused. Need to be careful to get conditions of loops correct. Humans often express the problem in a recursive way (rather than an iterative way).

Sequence

All instructions are executed once in the order in which they appear.

Advantages of SELECT over IF

All the alternatives depend on the value of one variable. So this makes the code clearer and easier to read/write. Allows multiple branches and avoids nested Ifs. Avoids numerous repeats of similar conditions.

Advantages of recursion

Can be easier to program or more intuitive with an inherently recursive algorithm.

Iteration

Code is executed repeatedly for a given number of times or until a condition is met.

Count controlled loop (FOR)

FOR loop is set up with a fixed number of iterations. Uses loop variable. E.g. FOR Count = 1 TO 10.....NEXT Count.

RETURN

Return tells the program to exit the function and supplies the value which will be used by the main program.

Identifier

Symbolic name given to a variable, constant or subroutine.

Program constructs

The three basic constructs are sequence, selection and iteration.

Disadvantages of recursion

Uses many sets of variables (one set per call) therefore less efficient use of memory and often slower and can run out of stack space causing run-time error.

Advantages of iteration

Uses only one set of variables so more efficient use of memory and can be faster. Less likely to run out of stack space.

SELECT (CASE)

Value of variable/expression used to decide which of a number of statement blocks is executed. There can be a default option.

Condition controlled loops (WHILE / REPEAT UNTIL)

WHILE loop runs repeatedly depending on a condition (it repeats while the condition is true. E.g. WHILE Count < 11..... END WHILE. REPEAT UNTIL loop repeats until some condition becomes true. E.g. REPEAT ... UNTIL Count > 10.

Nesting

When a construct is written completely contained within another. They are not allowed to overlap.


संबंधित स्टडी सेट्स

Cellular Respiration, THE MITOCHONDRIA IS THE POWERHOUSE OF THE CELL

View Set

OB EAQ's Chapter 10, 11, 12, 13, 14, 15, 16, 17

View Set

Chapter 13: Group Interventions - PrepU

View Set

7th Grade Accelerated Math - Chapter 3 Test/Rational Numbers Test

View Set

Chapter 7 - Financing and credit risk Part 2

View Set

Chapter 1.2.4.1: Project and Development Life Cycles

View Set

EPS 601 Chapter 3 (Ethical Issues in Counseling practice, study guide)

View Set

Honan-Chapter 23: Nursing Management: Patients With Gastric and Duodenal Disorders

View Set

CHP 10: DNA Polymorphisms and Human Identification

View Set