2.2.1 Programming Techniques Flashcards
Sequence
Code is executed line by line from top to bottom
Branching
Particular block of code is run if a specific condition is met
Uses IF and ELSE statements
Iteraction
Can either be:
. Count controlled - the code is run a specific number of times
. Condition controlled - the code is run until a specific condition is met
Uses For, While or Repeat Until loops
Recursion
Programming construct in which a subroutine calls itself in execution
Continues until a stopping condition is met
Advantages of Recursion
Can be represented in a fewer lines of code
Easier to express some functions recursively
Disadvantages of Recursion
Risk of stack overflow if memory runs out
Difficult to trace
Global and Local variables
. Variables can be defined with either global or local scope
. Scope is the section of code in which the variable can be accessed
. A local variable whithin a subroutine takes presedence over a global variable with the same name
Local variables
. Can only be accessed in the subroutine in which they were defined
. Multiple local variables with the same name can exist in different subroutines
. Are deleted once the subroutine ends
. Using local variables ensures subroutines are self contained
Global variables
. Can be accessed for the whole program
. useful for values that need to be used by multiple parts of the program
. Danger of being unintentionally edited
. not deleted until program terminates, so requires more memory
Modularity, functions and procedures
. Modular programming is a technique to split large, complex programs into smaller self contained modules
. Easier to divide tasks between teams and manage projects
. Simplifies the process of maintenance as each component can be dealt with individually
. Improves the reusability of components
Top down design/stepwise refinement
. Technique used to modularise programs
. Problem is broken down into sub-problems, until each is represented as an individual, self-contained module which performs a task
. Modules from blocks of code called subroutine
Functions and procedures
. Both named blocks of code that perform a specific task
. Procedures do not have to return a value
. Functions must always return a single value
. Parameters can be passed into a subroutine by value or reference
Passing by value
. A copy of the value is passed into the subroutine and discarded at the end
. Its value outside of the subroutine remains unaffected
Passing by reference
. Address of the parameter is given to the subroutine
. Value of the parameter will be updated at the given address
IDE (Integrated Development Environment)
. A program which requires a set of tools to make it easier for programmers to write, develop and debug code, features include
. Stepping
. Variable watch
. Breakpoint
. Source code editor
. Debugging tools