2.2.1 Programming techniques
No description yet. This curated deck is ready for daily study.
Card preview (17)
What are the three programming constructs?
-sequence -selection -iteration
What is sequence?
-executing instructions one after another
What is selection? Give an e.g
-allows a program to change direction depending on the outcome of a condition (boolean expression) -e.g an IF statement
What is iteration? Give an e.g
-repeating sections of code -could be a FOR loop (a count-controlled loop) -could be a WHILE, DO…UNTIL or a REPEAT…UNTIL loop (condition controlled loop)
What is recursion?
-when a subroutine (often a function) calls itself from within its own subroutine
What are the three characteristics of a recursive function?
-contains a stopping condition (base case) -the subroutine should call itself for any input value (other than the base case) -stopping condition should be reachable within a finite number of times
Why does a recursive function need these characteristics?
-it may call itself indefinitely, resulting in stack overflow
What is a local variable?
-declared inside a subroutine -only accessible by that subroutine -created when the subroutine is called -destroyed when the subroutine ends
What is a global variable?
-declared at the top of a program, outside of any subroutine -accessible throughout the program -created when the program starts -destroyed when the program ends
What is the problem with using global variables?
-can make programs hard to test, debug and maintain -using global variables is generally considered poor programming practice
What is a module? (4)
-procedure -function -subroutine -method
What is a procedure?
-a block of code that takes in zero, one or more parameters and performs a set task
What is a function?
-a block of code that takes in zero, one or more parameters; performs a set task; and returns a value
What is modularity?
-The concept of breaking a large program/ problem down into smaller chunks -each module carries out a single specific task
How do you pass data into a subroutine?
-by value -by reference
What is an IDE?
A program that provides a set of tools and related functionality designed to maximise a programmers productivity
common IDE features(7):
-code editors -error diagnostics (reports errors) -runtime environments -translators -auto documentation -syntax highlighting -autocompletion