Unit 11 - Programming Techniques Flashcards
define iteration
a sequence of instructions is repeated multiple times
examples of iteration
- for loop
- do…until
- while
difference between do…until and while loops
- while loop condition is tested at the start
- do..until condition is tested at the end. therefore code is always run at least once
define selection
changing the flow of the program
selection commands in LMC
BRA
BRZ
BRP
define IDE
Integrated Development Environment - software which enables you to enter, edit, compile (or interpret) and run your programs. many IDEs have debugging facilities to help you find the logic errors in a program
features of IDEs for code writing
- line numbers
- automatically indent code
- auto-complete commands
- comment or un-comment a region
features of IDEs for debugging
- set a breakpoint in the program which will cause the program to stop on that line
- set a watch on a variable so that its value is displayed each time it changes
- step through a program one line at a time
- trace the execution of the program
define identifier
name that points to the memory location
define assignment
assigning a value to a memory location
define variable
a named location in memory where data can be stored and that can be changed throughout the program
define constant
cannot be the target of an assignment as you have to change the source code and then recompile. reduce the risk of errors by reducing access to the memory location
define subroutine
a set of instructions with a name that when called changes the sequence of a program
difference between procedures and functions
- a function returns a value
- call statement differs
define parameters
appear in subroutine definitions and remain the same
define arguments
may change because they appear in subroutine calls
passing by reference(value)
the address of the argument calling the statement is passed to the corresponding parameter in the subroutine. any calculation performed on that parameter in the subroutine will change the value of the corresponding argument in the calling routine
define global variables
defined in the main program and can be re-used in subroutines
advantages of local variables
- subroutine will be independent of a particular program and can be re-used in different programs
- there is no chance of accidentally changing a variable in the main program that is used in a subroutine or vice versa
- subroutine is self-contained
- uses less memory
define modular programming
- means breaking down a major task into smaller subtasks
- these subtasks may be further broken down until each ‘module’ performs a single function
advantages of modular programming
programs are more quickly and easily written:
- large programs are broken down into subtasks that are easier to program and manage
- each module is individually tested
- modules can be re-used several times in a program
- large programs are much easier to debug and maintain
characteristics of recursion routines
- a stopping condition or base case must be included which when met means that the routine will not call itself and start to ‘unwind’
- for input values other than the stopping condition, the routine must call itself
- the stopping condition must be reached after a finite number of calls
use of call stack
- every time a subroutine is called, the return address is put on the call stack
- even with a stopping condition, the recursive routine can only be called a limited number of times or the stack will overflow with the maximum memory capacity