2.2 - Programming fundamentals Flashcards
What does + do?
Adds two variables
What does - do?
Subtracts two variables
What does * do?
Multiplies 2 variables
What does / do?
Divides 2 variables
What does % (MOD) do?
Outputs the remainder of the division
What does // (DIV) do?
Divides 2 variables but only shows the integer value (integer division)
What does == do?
Shows 2 strings are equal to each other
What does != do?
Shows 2 strings are not equal to each other
The 3 basic programming constructs
- Selection - the path a program takes when running based on a decision
- Sequence - executing one instruction after the other
- Iteration - the repeated execution of a section of code
What is a variable
A named memory location which stores a value that may change during the execution of the program
What is a constant
A value that cannot change when the program is run and is assigned when the program is made
What is assignment
Giving a variable or constant a value. This is done by an “=” sign
What is an identifier and rules that an identifier must follow
- The name of the variable
- It must start with a letter
- Cannot contain special characters
- Cannot have spaces
- NAme should be meaningful
Advantages of constants
- Make a program easier to read as they are declared at the start
- Can be changed in one single place instead of changing in multiple places meaning errors are reduced
- Compiler can optimise the code meaning it can be run more quickly when using constants
What is a case statement
- Where a program can branch off in several different paths depending on the value of a variable