Variables and Constants
Variable and constants are containers for storing a value.
Variable: Store of data which changes during execution of the program (due to user input)
Constant: Store of data that remains the same during the execution of the program.
Data Types
- Integers - Positive or negative whole numbers used with mathematical operators. 25
- Real/Float - A positive or negative number with fractional part. 25.0
- Char - A variable or constant that is a single character. ‘c’
- String - A variable or constant that is several characters in length. “ccc”
- Boolean - A variable or constant that can have only TRUE or FALSE.
Important Concepts
- Sequence – Statements are executed in order.
Example: Variables must first be declared, and then used.
- Selection – Allows data items to be picked according to given criteria.
Example: Finding the highest/smallest value
- Conditional Statements: An element of pseudocode which allows the algorithm to do different things depending on the input scenario. E.g. IF & CASE Statements
- Iteration – Causes statements to be repeated until a condition is met or until told to stop.
- Count Controlled Loops: A count-controlled loop is used when the number of iterations to occur is already known. E.g. (FOR…TO…NEXT)
- Post-condition Loop: The loop body is executed at least once before the condition is checked. If the condition is false initially, the loop body is still executed once.
E.g. (REPEAT…UNTIL…)
- Pre-conditional Loop: The condition is checked before entering the loop body. If the condition is false initially, the loop body is not executed at all. (WHILE…DO…ENDWHILE…)
- Linked with Chapter Seven, 7: Algorithm Design
- Totaling – Used with repetition, to keep the total updated.
Example: Total ← Total + Price
- Counting – Used with repetition to increment the counter by 1, the loop is repeated.
Example: Counter ← Counter + 1
String Handling
String handling involves manipulating and checking string data. Strings are sequences of characters, such as letters, numbers, spaces, or symbols, stored under a single identifier.
- Length: Determines the number of characters in a string, including spaces. len() / LENGTH
- Substring: Extracts a portion of a string. SUBSTRING(x,y,z)
- Upper: Converts all letters in a string to uppercase. variable.upper / UCASE(x)
- Lower: Converts all letters in a string to lowercase. variable.lower / LOWER(x)