2.2.1 Programming Techniques Flashcards
Name 3 programming constructs.
Sequence
Selection
Iteration
What is meant by sequence?
Code is executed line-by line from top to bottom
What is meant by selection?
Particular block of code is run if a specific condition is met
Which statements are examples of selection?
If
Else
Name the 2 types of iteration.
Count-controlled
Condition-controlled
What is meant by count-controlled iteration?
Block of code executed a certain number of times
What is meant by condition-controlled iteration?
Block of code executed while a condition is met
Which loops are examples of iteration?
For
While
What is recursion?
A programming construct in which a subroutine calls itself during its execution
How long does recursion continue?
Until a stopping condition is met
Give 2 advantages of recursion.
Can be represented in fewer lines of code
Easier to express some functions recursively
Give 2 disadvantages of recursion.
Risk of stack overflow if memory runs out
Difficult to trace
Which two ways can variables be defined?
Within a global scope
Within a local scope
What is meant by scope?
The section of code in which a variable can be accessed
Where can local variables be accessed?
Only within the subroutine in which they are defined
Where can global variables be accessed?
Across the whole program
What are 2 benefits of local variables?
Ensures subroutines are self-contained
Multiple local variables with the same name can exist in different subroutines
What are 2 disadvantages of global variables?
Requires more memory as not deleted until program terminates, local variables are deleted once the subroutine ends
Danger of being unintentionally edited
What is modular programming?
A technique used to split large, complex programs into smaller, self-contained modules
Give 3 benefits of using modular programming.
Improves reusability of components
Simplifies testing & maintenance
Easier project management
What is stepwise refinement / top-down design?
Technique used to modularise programs by breaking down problem into sub-problems until each is an individual, self-contained module performing a certain task
What is a function?
Named block of code that performs a specific task
Always returns a single value
What is a procedure?
Named block of code that performs a specific task
Do not have to return value
State the two methods by which parameters can be passed.
By reference
By value