CS Notes P2
CS Notes P2
CS Notes P2
represent
Variables and constants are used to store a single item of data in a program. This can
be accessed through the identifier. Variables can be changed during program execution
while constants remain the same.
Output refers to the process of displaying or saving the results of a program to the
user.Input refers to the process of providing data or information to a program
Sequence is a concept that involves executing instructions in a particular order
Selectionis a concept that allows you to execute different sets of instructions based on
certain conditions.
o IF statements allo w you to execute a set of instructions if a condition is true.
o IF… ELSE statements are used to execute one set of instructions if a condition
is true and a different set of statements if the condition is false.
o IF… ELSE… IF statements are used to test multiple conditions and execute
different statements for each condition.
o CASE statements allow you to execute different sets of instructions based on
the value of a variable.
Count-controlled loops
- A count-controlled loop is used when the number of iterations is known beforehand
- It is also known as a definite loop
- It uses a counter variable that is incremented or decremented after each iteration
- The loop continues until the counter reaches a specific value
Pre-condition loops
- A precondition loop is used when the number of iterations is not known beforehand and
is dependent on a condition being true
- It is also known as an indefinite loop
- The loop will continue to execute while the condition is true and will stop once the
condition becomes false
- It might not be iterated – even once.
Post-condition loops
- A post-condition loop is used when the loop must execute at least once, even if the
condition is false from the start
- The condition is checked at the end of the loop
Strings are a sequence of characters, such as letters, numbers, and symbols.
They are used to represent text in a computer program
String handling refers to the various operations that can be performed on
strings
Addition (+): Adds two values together
Subtraction (-): Subtracts one value from another
Division (/): Divides one value by another
Multiplication (*): Multiplies two values together
Exponentiation (^): Raises a number to a power
Boolean operators are logical operators that can be used to compare two or
more values and return a Boolean value (True or False) based on the
comparison. There are 3 you need to know:
o AND: Returns True if both conditions are True
o OR: Returns True if one or both conditions are True 4
o NOT: Returns the opposite of the condition (True if False, False if
True)
Library routines are pre-written code that can be used in programs to perform
specific tasks.
o Using library routines saves time by not having to write code from scratch
o Library routines are also tested and proven to work, so errors are less
likely
MOD: a function that returns the remainder when one number is divided by another
number
DIV: a function that returns the quotient when one number is divided by another number
ROUND: a function that rounds a number to a specified number of decimal places
RANDOM: a function that generates a random number between two extreme values
Files provide a way to store data permanently, allowing programs to access and
manipulate it later
Files allow for organised storage of data – especially large amounts - making it easier to
find, access, and update
They enable sharing of data between different programs and users
They support data backup, ensuring data is not lost when a program or computer system
shuts down
Data can be transported from one system to another