What are the three programming constructs?
What is sequence?
Instructions in a program are executed in the order they have been written.
What is iteration?
It allows sections of code to be repeated.
What is selection?
A program that changes direction depending on the outcome of a condition. They are usually shown using Boolean expressions (IF statement).It allows sections of code to be repeated.
What are the two types of loops?
What is a count-controlled loop?
A loop which is used when the required number of iterations is known ahead of execution.
What is a condition-controlled loop?
A loop with a condition at the start to determine if the iteration should occur or not. As long as the condition is met the iteration continues.
It is used when the number of required iterations are not known.
What is a nested construct?
What is recursion?
When a subroutine (often a function) calls itself from within its own subroutine.
What characteristics should a recursive subroutine exhibit?
What would happen if there wasn’t a base case, or the base case cannot be achieved in a finite number of times?
The subroutine would call itself indefinitely, taking up memory and resulting in a stack overflow. This could cause the program to crash.
Why is recursion not very efficient?
Every time a recursive function calls itself, the processor must remember the address it must jump back to later and the previous variables by using stacks, which takes up space in memory.
When is recursion needed rather than iteration?
What is the scope?
The scope of a variable refers to where it is accessible in the code. The scope is global or local.
What is a local variable?
What is a global variable?
What are the advantages of local variables?
What are the disadvantages of local variables?
What are the advantages of global variables?
What are the disadvantages of global variables?
What is a procedure?
A block of code that takes in zero, 1 or more parameters and performs a set task.
What is a function?
A block of code that takes in zero, 1 or more parameters; performs a set task and returns a value.
What is modularity?
The concept of breaking down a large problem/program into smaller parts.
The goal is to design the program in such a way that each module carries out a single specific task.
Why are functions used in modular programming?