You are on page 1of 6

# FLOW CONTROL

SEQUENCE IS ONE OF THE THREE BASIC BUILDING BLOCKS OF ALGORITHM DESIGN. IT IS A PROGRAMMING CONSTRUCT.

WHAT IS IT?
An algorithm consists of a series of steps. Sequence
refers to the order in which those steps are arranged
and carried out.

HOW IS IT USED?
It is important that the steps in a computer algorithm
are carried out in the correct order. Carrying out
steps in the wrong order may produce unexpected results
or errors in the program.

EXAMPLES
The algorithms below show the importance of sequence when calculating 5+3x2.

## FLOW DIAGRAM SCRATCH JAVASCRIPT

16
when clicked
var answer = 5 + 3;
set answer to 5 + 3
START START
say answer // output: 16
STATEMENT STATEMENT

5+3=8 3x2=6 11
when clicked var answer = 3 * 2;
STATEMENT STATEMENT set answer to 3 * 2 answer = 5 + answer;
8 x 2 = 16 5 + 6 = 11 set answer to 5 + answer console.log(answer);
say answer // output: 11
STATEMENT STATEMENT

FURTHER INVESTIGATION
END END
How does the use of functions or procedures affect
sequence in a program?
FLOW CONTROL

SELECTION
SELECTION IS ONE OF THE THREE BASIC BUILDING BLOCKS OF ALGORITHM DESIGN. IT IS A PROGRAMMING CONSTRUCT.

WHAT IS IT?
Algorithms often include decisions or choices about what
to do based on user input or the state of the program.
Decision making in progamming is known as selection.

HOW IS IT USED?
Selection is used when the algorithm needs to decide
whether to do something. It is also used to choose one
option from a number of options available. Selection
changes the path the program takes.

EXAMPLES
Each of the algorithms below outputs a message based on the users score.
FLOW DIAGRAM SCRATCH JAVASCRIPT

## if( score > 10 ) {

START
when clicked display("well done");
CONDITION if score > 10 then } else {
score > 10? display("try again");
say well done
YES NO
else
}
STATEMENT STATEMENT
say try again
output output
"well done" "try again"

## END FURTHER INVESTIGATION

There are different forms of selection (e.g. IF,
IF/ELSE or case statements). Find out how they work.
Find out how to combine more than one condition in
selection statements using logical operators.
FLOW CONTROL

ITERATION
ITERATION IS ONE OF THE THREE BASIC BUILDING BLOCKS OF ALGORITHM DESIGN. IT IS A PROGRAMMING CONSTRUCT.

WHAT IS IT?
Iteration is when a sequence of steps or operations are
repeated again and again until some condition is met.
It may also be referred to as repetition or a loop.

HOW IS IT USED?
Iteration is used when a sequence of steps should be
repeated a set number of times or until some condition
is met. Iteration is often used to step through lists
of items in arrays.

EXAMPLES
Each of the algorithms below outputs the numbers 1 through 10.
FLOW DIAGRAM SCRATCH JAVASCRIPT

## for( i=1; i<=10; i++ ){

START
when clicked console.log(i);
INITIALISATION
set i to i
}
i= 1
OR
repeat until i > 10
STATEMENT var i = 1;
output i say i while( i <= 10 ) {
STATEMENT change i by 1 console.log(i);
NO i+1 wait 1 secs i++;
}
CONDITION

FURTHER INVESTIGATION
YES There are different forms of iteration (e.g. counter
or condition controlled). Find out how they work.
END
Find out how to use iteration to step through arrays.
FLOW CONTROL

SEQUENCE IS ONE OF THE THREE BASIC BUILDING BLOCKS OF ALGORITHM DESIGN. IT IS A PROGRAMMING CONSTRUCT.

WHAT IS IT?
An algorithm consists of a series of steps. Sequence
refers to the order in which those steps are arranged
and carried out.

HOW IS IT USED?
It is important that the steps in a computer algorithm
are carried out in the correct order. Carrying out
steps in the wrong order may produce unexpected results
or errors in the program.

EXAMPLES
The algorithms below show the importance of sequence when calculating 5+3x2.

## FLOW DIAGRAM SCRATCH PYTHON

16
when clicked
set answer to 5 + 3
START START
say answer // output: 16
STATEMENT STATEMENT

5+3=8 3x2=6 11
when clicked answer = 3*2
STATEMENT STATEMENT set answer to 3 * 2 answer = 5+answer
8 x 2 = 16 5 + 6 = 11 set answer to 5 + answer print(answer)
say answer // output: 11
STATEMENT STATEMENT

FURTHER INVESTIGATION
END END
How does the use of functions or procedures affect
sequence in a program?
FLOW CONTROL

SELECTION
SELECTION IS ONE OF THE THREE BASIC BUILDING BLOCKS OF ALGORITHM DESIGN. IT IS A PROGRAMMING CONSTRUCT.

WHAT IS IT?
Algorithms often include decisions or choices about what
to do based on user input or the state of the program.
Decision making in progamming is known as selection.

HOW IS IT USED?
Selection is used when the algorithm needs to decide
whether to do something. It is also used to choose one
option from a number of options available. Selection
changes the path the program takes.

EXAMPLES
Each of the algorithms below outputs a message based on the users score.
FLOW DIAGRAM SCRATCH PYTHON

## if score > 10:

START
when clicked print("well done")
CONDITION if score > 10 then elif:
score > 10? print("try again")
say well done
YES NO
else
STATEMENT STATEMENT
say try again
output output
"well done" "try again"

## END FURTHER INVESTIGATION

There are different forms of selection (e.g. IF,
IF/ELSE or case statements). Find out how they work.
Find out how to combine more than one condition in
selection statements using logical operators.
FLOW CONTROL

ITERATION
ITERATION IS ONE OF THE THREE BASIC BUILDING BLOCKS OF ALGORITHM DESIGN. IT IS A PROGRAMMING CONSTRUCT.

WHAT IS IT?
Iteration is when a sequence of steps or operations are
repeated again and again until some condition is met.
It may also be referred to as repetition or a loop.

HOW IS IT USED?
Iteration is used when a sequence of steps should be
repeated a set number of times or until some condition
is met. Iteration is often used to step through lists
of items in arrays.

EXAMPLES
Each of the algorithms below outputs the numbers 1 through 10.
FLOW DIAGRAM SCRATCH PYTHON

## START for i in range(10):

when clicked
INITIALISATION
print(i+1)
set i to i
i= 1
repeat until i > 10 OR
STATEMENT

output i say i i = 1
change i by 1
while i <= 10:
STATEMENT
NO i+1 wait 1 secs print(i)
i += 1
CONDITION