Programming Techniques

Cards (16)

  • What are the programming constructs?
    Sequence, selection, iteration
  • What is sequence? Series of logical steps that are performed in a given order
  • What are some common examples of sequence? Variable initialisation and print statements
  • What is branching/selection? Instructions which can evaluate a Boolean expression and then jump the code to one or more alternative paths
  • What are some common examples of selection? IF statements and CASE statements
  • What is iteration? Section of code which can be repeated either a set number of times (count controlled) or a variable number of times based on the evaluation of a Boolean expression (condition controlled)
  • What are the three main types of loops: Infinite, count controlled, condition controlled
  • What is an infinite loop? Section of code which keeps repeating until the user terminates the program or it crashes
  • What is a possible use of an infinite loop? An operating system continually checking for user input and responding accordingly until the device is turned off or reset
  • When would a count controlled loop be used? When the number of necessary iterations is known
  • When would a condition controlled loop be used? When the number of necessary iterations is not known but is based on a condition
  • What is a branch? Instruction in a computer program that can cause the computer to begin executing a different instruction sequence, deviating from its default behaviour of executing instructions in order
  • What does scope refer to? Area where a function or variable is visible and accessible to other code
  • What is a global variable? Variable which can be used anywhere in the program
  • What is a local variable? Variable which is defined and can only be used within one part of the program (normally a single function or procedure)
  • Why should local variables be used wherever possible? Excessive and unnecessary use of global variables can make programs hard to test, debug and maintain