slr23 - programming constructs Flashcards
Describe sequence
The default mode for code to work in: executing instruction one after another
Describe selection
Allows a program to change direction depending on the outcome of a condition
Describe iteration
Also called looping: enables us to repeat lines of code
What is recursion
When a subroutine calls itself from within its own subroutine
What are the features of recursion
Contains a stopping condition
For any value other than the stopping condition the subroutine should stop itself
The stopping condition should be reachable in a finite amount of times
What causes a stack overflow in relation to recursion
When a recursive function calls itself indefinitely
When is recursion used
Tree traversal algorithems
What is the scope of a variable
From where in the program it can be accessed from
What is a local variable
A var that can only be accessed from inside of a specific subroutine
What is a global variable
A var that can be accessed from anywhere in the program
Why is it sometimes better to use local variables
In large programs global vars can be confusing
Global vars are not deleted after they have been used therefore they take up more space in memory
What is a function
A block of code that:
Takes in parameters
Performs a set task
returns a value
What is a procedure
A block of code that:
Takes in parameters
Performs a set task
What are parameters
Values that are passed into a function
Passing by reference
References the location in memory
This means that the value can be changed