2.2.1 Programming Techniques

Programming constructs

There are different programming constructs. These are the ways in which a program can be written and run, sequence, selection and iteration.

sequence

Sequence of Statements(constructs used in Structured Programming)

The sequence construct follows the basic top to bottom principle. the lines are run from top to bottom in the order in which they occur. This construct on it’s own is extremely limiting.

Selection

Conditional (computer programming) - Wikipedia

This construct allows for the use of choice when running a program. When run the program will can do different things based on conditions. This allows for the implementation of “If” statements.

Iteration

Programming in C++ Language PDf Free Download Interview, Exampl

iteration repeats a process until a told otherwise. There are 2 types of iterative constructs these are; count controlled loops (for) and condition controlled loops (while).

a condition controlled loop will repeat a process until a condition is met(while x == true) where a count controlled loop will repeat a process until a certain counter reaches a given/known limit.(for x in range 10)

The C Programming Language | ICT - Seneca

Global and Local variables

Local variable:

a local variable is declared and used inside a sub-routine and only available to that routine. Created when the routine is called and destroyed when it ends.

Global variable:

Declared at the top of a program outside of a sub-routine. The global variable is usable throughout the program, created when the program starts and destroyed when it ends.


Functions and procedures

Procedures:

Takes zero, one or more perimeters when called and carries out a set task NOT returning a value.

Functuons:

Takes zero, one or more perimeters when called, carries out a set task and DOES return a value.

calling a passing values to a function or procedure can be can either be done by value or reference
x = 1
y = 2
function(x, y)
OR
function(1, 2)


IDEs (Integrated Development Environment)

IDEs have lots of helpful features for writing and debugging code E.G


Recursion Vs Iteration

Recursion is where a sub-routine (often a function) calls itself. This act, creating a loop, is what is called recursion. These sub-routines must contain a stopping condition (Base case). for any input values other than the stopping condition the function must call itself (Recursion) and this stopping condition must be reachable after a finite number of times.


Object orientated techniques

Object oriented programming is best used for grouping things together and interacting different items that can be modelled as objects. It is useful in the creation of GUIs as things like buttons have lots of different variables attached to them, E.G: position, state, colour etc.

Create your own website, free on WordPress.com.Create your own website.
Start free