Programming Concepts Flashcards
(42 cards)
What is a variable?
A variable is an identifier that can change in the lifetime of a program.
What are the four variable requirements?
- In mixed case (Pascal case)
- Only contain letters (A-Z, a-z)
- Only contain digits (0-9)
- Start with a capital letter and not a digit
Example variable declaration
DECLARE GameOver : BOOLEAN
What is a constant
A constant is an identifier set once in the lifetime of a program generally named in all uppercase letters.
INTEGER
Whole numbers: 5, 0, -5
REAL
Numbers with a fractional part (decimal): 3.14, -2.5, 0.0
CHAR
Single character: ‘a’, ‘B’, ‘6’, ‘£’
STRING
Sequence of characters: “Hello world”, “ABC”, “@#!%”
BOOLEAN
True or false values: True, False
INPUT and OUTPUT example
INPUT Answer
OUTPUT “Your answer is”, Answer
What is sequence?
- Sequence is when lines of code run one after another in the order they are written, from first to last.
- It is essential for the correct flow of a program — instructions out of order can cause errors or unexpected results.
IF Statements syntax
IF Answer ← “Yes”
THEN
OUTPUT “Correct”
ELSE
OUTPUT “Wrong”
ENDIF
CASE OF Statements syntax
INPUT Move
CASE OF Move
‘W’ : Position ← Position - 10
‘E’ : Position ← Position + 10
‘A’ : Position ← Position - 1
‘D’ : Position ← Position + 1
OTHERWISE
OUTPUT “Beep”
ENDCASE
What are the two type of selection statements?
- IF Statements
- CASE OF Statements
What are the two type of condition - controlled loops?
- While Loops
- Repeat Until Loops
What is an example of a count - controlled loop?
- FOR Loops
FOR Statements syntax
FOR X ← 1 TO 10
OUTPUT “Hello”
NEXT X
WHILE Loops syntax
INPUT Temperature
WHILE Temperature > 37 DO
OUTPUT “Patient has a fever”
INPUT temperature
END WHILE
REPEAT UNTIL Statements Syntax
REPEAT
INPUT Colour
UNTIL Colour ← “red”
Totalling Syntax
Total ← 0
FOR I ← 1 to 10
INPUT Num
TOTAL ← TOTAL + Num
NEXT I
OUTPUT Total
Counting Syntax
Count ← 0
FOR I ← 1 to 10
INPUT Num
IF Num > 5
THEN
Count ← Count + 1
ENDIF
NEXT I
OUTPUT Count
String Handling Uppercase
Name ← “Sarah”
OUTPUT UCASE(Name)
String Handling Lowercase
Name ← “SARAH”
OUTPUT LCASE(Name)
String Handling Length
Password ← “letmein”
OUTPUT LENGTH(Password)