programming Flashcards
what is a variable
a memory location that is used to temporarily hold data value,
it can change while program is running
benefits of subprograms:
easier to maintain: code is shorter, easier to understand
avoids repetition of code: sub can be called instead of copying/pasting, quicker to develop new programs
work can be delegated between team members, reduces development time
count controlled loop to print out numbers 1 to 10 in ascending order
for i = 1 to 10
print i
next i
what is high level language:
aimed to be understood by humans, has to be translated before it can be run
Integrated Development Environment tools:
editor, to enable program code to be entered/ edited
translator, to enable code to be executed
three programming constructs:
selection
iteration
sequence
local variable advantages
saves memory - only uses memory when that local variable is needed - global variables use memory even if not used
easier to debug local variables as they can only be changed within one subroutine
you can reuse subroutines with local variables in other programs
global variable advantages
variables can be used anywhere in the whole program (and in multiple subroutines)
makes maintenance easier as they are only declared once
can be used for constants - values that remain the same
what is casting?
changing the data type of a variable to another data type
why is casting needed?
-to concatenate two strings, the ALU needs to use numbers to perform the arithmetic operation
-therefore string needs to be ‘cast’ to a number
-integers require less bits of memory than real. numbers
what is a boolean data type?
-true or false
-used to track if something has happened or happened or not
return a string length:
length = string.length
convert a string to all upper/lower case
ustring = string.upper
lstring = string.lower
extract the ‘mat’ letter from
string = “tomato”
chars = string.substring(2,3)
output PUT from someText = “Computer Science”
print ((someText.substring(3,3).upper)