2.2.1 Programming Techniques Flashcards
1
Q
What is programming
A
- Is the process of creating a set of instructions that can be executed by the computer
- There are many different programming paradigms (models), including object-oriented, procedural, functional and declarative
2
Q
What is a Sequence
A
- Sequence means that each instruction is executed once in the order given before moving onto the next Instructions = statements
3
Q
What is Branching
A
- Sequence is a vital programming construct, but there are many situations in which you wont want the computer to execute every instruction given.
- There are 3 implemetations of branching commonly available in programming languages
- IF statements
- ELIF (ELSE IF statements)
- ELSE (IF ELSE statements)
4
Q
What are IF statements
A
- IF statements are the most basic form of branching
- They check if a condition has been met, and if it has its value is set to TRUE and the program will set execute the set of instructions
5
Q
What is IF ELSE statements
A
- Similar to IF statement but if the condition necessary is not met, the instructions within the ELSE statements are executed instead.
6
Q
What are ELIF (ELSE IF) statements
A
- This combines IF and IF ELSE statements.
- If the condition necessary to execute the instructions of IF statement, ELIF is checked
7
Q
What is SELECT CASE
A
- Another common form of selection.
- SELECT case focuses on the content of a variable and has a separate CASE for each outcome
- Another important part is CASE ELSE statement at the end of SELECT CASE. This will be executed if none other cases apply.
- Using SELECT CASE avoids the need to use multiple nested IF statements - difficult to read.
8
Q
What is Iteration
A
- Iteration is used to execute the same instruction a same number of times or until a condition is met.
- Most programming languages support 2 types: WHILE and FOR loops.
9
Q
What are FOR loops
A
- FOR loops execute an instruction a set number of times. This is count controlled. We create a count and set it to 0.
- Every time the code is executed the count is increased by 1 - when count reaches value set by programmer, the computer stops executing the code
10
Q
What are WHILE loops
A
- Are used to repeat an instruction until a condition is met - known as condition controlled loops.
11
Q
What is Nesting
A
- Is the name given to the practice of placing one construct within another.
- Example IF statement inside an IF statement
12
Q
What is Recursion
A
- A recursive function is one that repeatedly calls itself until a base case is met within a function
- Can be used to calculate factorial of a given whole number - calculated repeatedly
13
Q
What are the advantages of recursion over iteration?
A
- More natural to read (1)
- Quicker to write / less lines of code. (1)
- As some functions are naturally recursive (1) Suited to certain problems (1)
- For example those using trees (1)
- Can reduce the size of a problem with each call.
14
Q
What are examples of data types
A
- Char - A single character
- String - A series of letters and numbers
- Boolean - Either TRUE or FALSE
- Integer - A whole number
- Float - A decimal number
15
Q
What is a Variable
A
- Identifier/name of a …
- Memory location used to store data