Programming Elements Flashcards
Identifier
A unique name for something (e.g. variable, constant, procedure, etc.) within the program
Variable
An identifier associated with a specific memory location, used to store data. Its value can change while a program runs
Constant
A named value within a program with a fixed value that does not change while the program runs
What are the benefits of declaring a constant? (2)
- When its value changes, only the declaration has to be changed
- It makes your code easier to read, debug and maintain
Why aren’t variable names beginning with underscores encouraged?
A considerable number of names beginning with underscores are already reserved for use by the system
Data type
The type of data stored in a variable
What does the data type of a variable define? (3)
- The type of data stored in a variable
- How much memory is needed to store it
- The operations that can be performed on it
Integer
Data type for whole numbers
Real OR Float
Data type for fractional numbers
Character
Data type for a single character
String
Data type for text (over 1 character). Sometimes limited to a length of 255 characters
Boolean
A true or false value
How much memory is typically needed to store:
- An integer?
- A float?
- A single character?
- A boolean?
- 2 or 4 bytes
- 4 or 8 bytes
- 1 byte
- 1 byte, although 1 bit would suffice
Assignment
When a variable is given a value
Initialisation
Explicitly setting the starting values of variables
Algorithm
A series of instructions that solves a specific problem
What are the three main parts of program flow control?
- Sequence
- Selection
- Iteration
Sequence
Where instructions are executed one after another in series
Selection
Where the program executes certain instructions based on a condition
The two basic selection constructs are…
- If/else statements
- Case statements*
*Do not exist in Python
Boolean expression
An expression that evaluates to true or false
Logical operators
NOT, AND, OR and XOR. Used in conditions and Boolean expressions.
Relational operators
Operators that compare two values
Iteration
Where a program executes a group of instructions zero or more times based on a condition
What are the three types of iteration loop constructs?
- While
- Repeat/until*
- For
*Do not exist in Python
How many times does each loop construct run?
While loops: zero or more times
Repeat/until loops*: at least once
For loops: a specific number of times
*Do not exist in Python
Condition
A Boolean expression that controls an iteration or selection statement
Structure chart
A diagram showing how a code module breaks down into smaller modules through sequence, selection and iteration
Flowchart
A diagram using commonly defined symbols to express an algorithm
Pseudocode
A way of writing an algorithm using programming constructs, but not in an actual language