1.2.4 types of programming language Flashcards
this deck only contains part (SLR08) of 1.2.4 as theres more stuff on paper. reference screenshots on phone for photos of example code etc (7th june 2024)
what is a computer program
- series of statements (instructions) that are executed one after another
all but the most trivial (insignificant) of programs tend to do what 3 things
- accept input
- process data
- produce output
what are the 3 programming constructs (used in procedural languages)
- sequence
- selection
- iteration
what is sequencing
- executing instructions one after another
what is selection
- allows a program to branch and follow a different direction depending on outcome of a certain condition
what is iteration
- repeating / looping sections of code
how do you create an infinite loop
WHILE True
what is a FOR loop (type and what does it mean)
- count-controlled loop
- used when required number of iterations is known ahead of execution
what is a WHILE loop (type and what does it mean)
- condition-controlled loop
- used when required number of iterations isn’t known because the variable used to determine when the iteration ends is changing within the iteration itself
what is a DO… UNTIL loop
- alternative to WHILE where the code executes at least once before condition is checked
what is the difference between WHILE loop and DO…UNTIL loop
- WHILE loop, condition checked at start (if condition met, we may never execute the following lines of code in WHILE loop)
- DO… UNTIL loop always executes code once before checking exit condition at end
what do programming constructs do
- control flow of program
What is program flow?
The path that a program follows as it runs from start to finish.
what is nesting
- process of putting one statement inside another
- this can be achieved through both iteration and selection statements
What is a variable?
- pointer to a memory location that holds a value. It is defined by a name/label.
CAN BE CHANGED WHILE THE PROGRAM IS RUNNING.
What is a constant?
- a memory location that holds a value. It is defined by a name/label
CANNOT BE CHANGED WHILE THE PROGRAM IS RUNNING
what is a subroutine
- block of code given a unique, identifiable name within a program
why do we use subroutines
- break down larger problem into series of smaller + more manageable problems
- this makes code easier to write, debug and test
- creates reusable components
What is a similarity and a difference between a procedure and a function?
- Both are blocks of code (provide structure to code) which carry out a set task
- they are defined under a name which can be called and run simply by stating name of the function / procedure.
- Functions return values whereas procedures only execute commands.
- functions also create reusable program components
what are procedures and functions similar to in OOP
- methods
what is casting
- converting value into a different data type
- e.g string to integer using command int
Give examples of arithmetic operators.
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
^ or ** (exponentiation)
MOD or % (remainder)
DIV or // (e.g 7 DIV 2 = 3, its the nearest integer answer)
Give examples of comparison operators.
== (equal to)
!= (not equal to)
< (less than)
<= (less than or equal to)
> (greater than)
>= (greater than or equal to)
Give examples of boolean operators.
AND / OR / NOT / XOR