Programming techniques (2.2.1) Flashcards
What are the three main programming constructs?
- Sequence
- Selection
- Iteration
What is sequence?
Code is execute line by line from top to bottom
What is selection?
A specific block of code is run if a specific condition is met, using IF statements.
What is iteration?
A block of code is executed a set number of times or while/until a condition is met using FOR, WHILE or REPEAT UNTIL loops.
What is the scope of a variable?
It refers to the section of code where the variable is available.
What are the two main variable scopes?
- Local
- Global
What is a local variable?
A variable that can only be accessed in the block of code in which they are defined.
Local variable ADVS
Ensures subroutines are self-contained i.e. the variable are not affected by code outside of the subroutine
What is a global variable?
Can be accessed throughout the whole program.
Global variable ADVS
Useful for values that need to be used by multiple parts of the program
Global variable DISADVS
- Can be unintentionally overwritten.
- Require more memory than local variables
What is modular programming?
A technique used to split large, complex programs into smaller, self-contained modules.
Modular programming ADVS
- Makes problems easier to understand and approach
- Can divide tasks between a team
- Simplifies testing and maintenance, can deal with each component individually
- Code is reusable
Modular programming DISADVS
- Can cause complexity in simple programs
- May be challenging to keep track of function names and values
What are functions and procedures?
Blocks of codes that perform a specific task