3.2 Programming Flashcards
String
Str
Statement
Integer
Int
Number
Float
Float
Decimal
Bool
Boolean
True/false
Real
Real
Decimal
Iteration
Repeating sections of code in a loop.
FOR, WHILE, REPEAT
Selection
Changing the direction of a programme based on a specific criteria
IF, SELECT, CASE
Indefinite loop
If you don’t know beforehand how many times the loop will repeat, you use an indefinite loop.
This is also called a condition-controlled loop because you decide when to stop looping depending on how a condition is set.
Pre-controlled loops
The condition is checked before the loop starts and will keep going whilst the condition is TRUE.
WHILE count < 5
count <— count + 1
ENDWHILE
Post-controlled loop
REPEAT
count <— count + 1
UNTIL count < 5
Definite loop
If you do know how many times the loop will repeat, you use a definite loop. This is also called a counter-controlled loop because the loop will repeat until the counter reaches a certain value.
FOR count <— 1 to 5
OUTPUT count
ENDFOR
Nested loops
Loops inside one another. The loop in the middle will then repeat every time for the outside loop.
FOR multiple <— 1 to 10
OUTPUT multiple + “times table”
FOR count <— 1 to 5
OUTPUT count *multiple
ENDFOR
ENDFOR
Nested IF statements
We can use multiple if statements within each other.
IF count < 10 THEN
IF count < 5 THEN
OUTPUT “Fail”
ELSE
OUTPUT “Pass”
ENDIF
ELSE
OUTPUT “Merit”
ENDIF
Relational operators:
Less than
<
Relational operators:
Greater than
>
Relational operators:
Equals
=
Relational operators:
Not equals
!=
Relational operators:
Less than or equal to
<=
Relational operators:
Greater than or equal to
> =
Arithmetic operators
• Addition
• Subtraction
• Multiplication *
• Division
• MOD
• DIV
Division
Gives a real number (decimal) as the result.
/
MOD
Finds the remainder when the first number is divided by the second.
%
DIV
Finds the whole part when the first number is divided by the second.
//
Boolean operators
Boolean operators refer to being able to compare one or two Boolean values and return either TRUE or FALSE.
NOT
This revers the input.
NOT TRUE = FALSE
AND
This checks if both inputs are TRUE and returns TRUE if so, FALSE otherwise.
OR
This checks if either input is TRUE and returns TRUE if so, FALSE otherwise.