Paper 1 Flashcards
Selection?
IF….ELSE
Iteration?
FOR….ENDFOR
WHILE….ENDWHILE
REPEAT…UNTIL
4 different sorts?
Linear search
Bubble sort
Merge sort
What is FOR…ENDFOR loop an example of?
definite iteration
What is WHILE…ENDWHILE loop an example of?
indefinite iteration
What is REPEAT…UNTIL loop an example of?
indefinite iteration
What is a subroutine?
A named, self-contained section of code that performs a specific task.
What are the 2 different types of subroutines?
- procedures (nothing is returned)
- functions (always returns a value using RETURN)
What are advantages of subroutines?
- easier to de-bug
- more robust
- Decomposing large problems into sub-tasks, making the problem easier to solve
- Each subroutine can be tester separately
- Can be used several times within a program
- Maintenance is easier
Define global variable?
A global variable is one which is declared in the main program and is recognised in al subroutines called from the main program.
Define local variable.
Declared within the subroutine and only existing whole the function is being executed. Not recognised anywhere else in the program.
Advantages of using local variables
- keeps the subroutine self-contained. Can be used in any program and there will be no confusion over which variable names in the main program might conflict with names used in a subroutine.
- Easier to debug and maintain
- If memory space is an issue, the use of local variables will save on memory as the space used by local variables is freed up when the subroutine completes
- form of abstraction
How to make a code more understandable?
- Use comments to say the purpose of the program/ explain how any difficult bit of code works
- Split the program into subroutines which each perform a single well-defined task
- Use meaningful variables
- Use indentation so that it is clear where iteration and selection statements end
- Use constant variables for values such as VAT rate
What is a syntax error?
- spelling mistake (prnt instead of print)
- missing key words out of constructs such as starting REPEAT loop but not writing UNTIL anywhere
- opening brackets but not closing them
What are logic errors?
- missing brackets for mathematical equations
- Loops that do not execute the correct number of times because a condition is written wrong e.g x > 10 instead of x >= 10
- variables have not been initialised or are initialised in the wrong place
- flawed algorithms that don’t do what they were intended too