what are some common programming constructs used in structured programming?
define “sequence”
code is executed line by line, from top to bottom
what is selection?
when a question is asked which has a Boolean answer, and depending on the answer the program takes 1 of 2 courses of action, after which the program moves onto the next event
ie. an if… then… else… statement
when are nested if statements used and what do they look like?
used when it isn’t enough to ask one question:
if….
….
if…..
…..
what are case statements?
use these to ask lots of questions (in Python this is an elif statement)
Example:
case k of:
1: print(“gold”)
2: print(“silver”)
3: print(“bronze”)
what is iteration?
a process wherein a set of instructions or structures are repeated in a sequence a specified number of times or until a condition is met
what are the 2 major groups of loops?
what is a count controlled loop?
a loop which repeats the instructions within it until the counter reaches a certain value
eg. a for… next loop
what is a condition controlled loop?
a loop which repeats the instructions within until a condition is met (this may still be a value)
eg. a while… loop
what is a post test iteration? give an example
tests the condition at the end of the sequence so will always be run once
example:
repeat
print “hello world”
x = x+1
until x = 10
what is a pre test iteration?
condition is checked before entry into the iteration so if the condition isn’t met, it won’t run
Example:
while x < 10:
print “hello world”
x = x+1
endwhile
what is branching?
when control is passed to a different sequence of instructions, rather than completing the next line
eg. in assembly: BRA, BRZ, BRP
used for functional + procedural calls
how does branching work?
uses a stack to keep track of each branch call, so that it can retrace its steps back to the main program
what is a function?
a subprogram that can be called from elsewhere in the program - interrupting the natural sequence of the program
returns a value to the main program
can have parameters
what is a procedure?
almost the same as a function but doesn’t return a value on completion
what is a library?
a collection of functions
what are the basic rules that apply to loop structures?
what are some advantages of using the case structure over nested if statements?
what are some advantages of using nested if statements over the case structure?
what is a recursive function?
how does recursion work?
what is a stack overflow error?
call stack running out of memory to contain stack frames created during recursion
what are the advantages of recursion?
what are the disadvantages of recursion?