Programming Techniques Flashcards
Sequence, iteration, branching Global and Local Variables Recursive functions Modularity, functions and procedures Features of an IDE
Define Sequence
Code that is executed line-by-line, from top to bottom
Define Branching
A certain block of code that is run if a specific condition is met, using IF
statements
What is branching similar to?
Selection
Define Iteration
A block of code that is executed a certain number of times or while a condition is
met. Iteration uses FOR, WHILE or REPEAT UNTIL loops
Define count controlled iteration
Iteration is repeated a given number of times
Define condition controlled iteration
Iteration continues until a given condition is met
Define recursion
Recursion is a programming construct in which a subroutine
calls itself during its execution
When does the recursion end?
When the stopping condition is met
What also produces the same result as recursion?
Iteration
Give an advantage of recursion
The advantage of using recursion for certain problems is that
they can be represented in fewer lines of code, which makes them less prone to errors
Give a disadvantage of recursion
Inefficient use of
memory. If the subroutine calls itself too many times, there is a danger of a stack overflow,
which is when the call stack runs out of memory. This would cause the program to crash. Another problem with recursion is that it is difficult to trace,
especially with more and more function calls
What type of recursion uses less stack space?
Tail recursion
Define scope
Refers to the section of
code in which the variable is available
Define local variable
A variable with limited scope which means that they
can only be accessed within the block of code in which they
were defined
Give an advantage of using local variables
Multiple local variables with the same name can
exist in different subroutines and will remain unaffected by
each other. Therefore variables cannot be accidentally overwritten