Programming concepts Flashcards
Programming data types
INTEGER STRING REAL CHAR BOOLEAN
INTEGER
Stores a whole number
STRING
Stores zero or more sequence of characters
REAL
Stores integers and numbers with a decimal part
CHAR
Stores a single character
BOOLEAN
Stores only 2 possible values
variable
named memory location that can store a value
value can change whilst the program is running
constant
named value
cannot change whilst program is running
Advantages of constants
- code will be easier to read and understand (constant’s identifier will be used instead of a number)
- you only have to edit in one place.
- value cannot be accidentally changed during the running of the program
counting
count the number of items in a list
incremented by 1
count ← count + 1
totalling
sum a list of numbers
each value is added to a running total
total ← total + value
sequencing
idea of one statement or instruction being executed one after another
selection
decides which statements are executed based on a condition
2 conditional statements(selections)
IF … THEN … ELSE … ENDIF
CASE … OF … OTHERWISE … ENDCASE
CASE … OF … OTHERWISE … ENDCASE
A statement that allows for multiple selections/deals with many possible outcomes
simplifies pseudocode and make it easier to read
IF … THEN … ELSE … ENDIF
A conditional statement with different outcomes for true and false
Loop(iteration structures)
FOR … TO … NEXT
WHILE … DO … ENDWHILE
REPEAT … UNTIL
FOR … TO … NEXT
loop that will iterate a set number of times
Used when you know how many times you want to iterate
WHILE … DO … ENDWHILE
condition-controlled loop
Condition is checked at the start of the loop
code inside the loop may therefore not execute
Used when you do not know how many times to iterate
REPEAT … UNTIL
condition-controlled loop
Condition is checked at the end of the loop
code inside the loop will always execute at least once
Used when you do not know how many times to iterate
Array
e.g. data structure
Collection of variables of the same data type
Referred to by a single name (identifier)
Each element is accessed by an index (position)
4 advantages of an array
- can store multiple values under a single identifier
- reduces the number of variables
- can use iteration to loop through an array
- allows for more efficient programming