2.2 Problem solving and programming Flashcards
Why are programming constructs used?
to represent the programs control flow
Give three constructs of structured programming.
Sequence, branching and iteration
What is the programming construct of sequence?
the code is executed line-by line, from top to bottom
What is the programming construct of Branching/selection ?
the block of code is run if a specific condition is met.
What is the programming construct of iteration?
the block of code is executed a certain number of times or while a condition is met.
What are the two types of iteration?
Count- controlled and condition controlled
What is Count-controlled iteration?
the iteration is repeated a give number of times
What is Condition-controlled
the iteration continues until a specific condition is met
What is Recursion?
a programming construct in which a subroutine calls itself during its execution until a stopping condition is met.
What are the advantages of Recursion?
reduces lines of code and is less prone to errors
What are the disadvantages of Recursion?
its an inefficient use of memory (can cause a stack over) and is difficult to trace
What are the two types of error?
Logic and syntax errors
What is a Logic error?
when the program works, but not in the intended way, produce an unexpected output
What is a Syntax error?
when the rules of the programming language have been broken
What is a Scope?
it refers to the section of code in which the variable is available.