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