2.2.1 Programming Techniques Flashcards
Sequence
Execution of statements or functions one after another
Iteration
Where a section of code is repeated, controlled by a Boolean expression
Can be count-controlled (for) or condition-controlled (while)
Branching/selection
Where a section of code is executed based on a condition, controlled by a Boolean expression
Local Variables
They are declared inside a subprogram and are only visible from that subprogram. The data is lost at the end of the subprogram and they can overwrite global variables
They are stored in RAM in the stack or the heap
Local Variables Advantages
+ Less likely to be altered by other modules
+ Allows code to be reused as libraries
Global Variables
Declared outside any subprograms, can be accessed from anywhere in the program.
Stored in RAM in a section called Data
Global Variables Advantages
+ Can be called anywhere in the program
+ Useful if various subprograms read/write
Subroutine
A section of code that performs a specific task
Functions vs procedures
Functions return a value, procedures do not
Parameter passing
Arguments in brackets are used to pass data to a subroutine e.g. multiply(x,y)
Can be by value or by reference
Passing by value
A local copy of the value of the data is passed so the value of the original data is unchanged
Object
A thing that has data (attributes) with operations that can be called on that data (methods)
Attributes
A property of the object
Shape could be one, round could not
Class
A blueprint for an object
Constructor
A method that is used to create objects based on the class
Encapsulation
Wraps the attributes and methods in the class definition, hiding details of the implementation from the user Attributes are made private and can only be accessed through public methods
Pseudocode to define a class
class Classname
private attributes
…
end class