Preview

08 - Program Flow

 1. Read the paragraph below and fill in the blanks.
Algorithms use _____________ to make decisions about which order to do things. 
They can repeat actions or start new actions based on new information.
Computer programs use _______,  ________ and ________ to control the
flow of the program. These elements allow the program to make choices, 
change direction or repeat actions.

  control flow / sequence / selection / iteration

  sequence / selection / control flow / loops

  if statements only / sequence / control flow / loops

  selection only / control flow / sequence / iteration

 2. The most basic algorithm, like the example below, uses ____________ to present a list of instructions to be followed one after the other, step by step.
unlock the door
open the door
enter the room
switch on the light
close the door behind you

  sequence

  iteration

  selection

  control ifs

 3. IF-THEN-ELSE looks for the correct option from two choices where CASE looks at the correct option from multiple choices. This also helps control the flow of a program and in this case is called Iteration.

  False

  True

 4. Iteration is a key tool in program flow. It is the process of __________sections of a program to achieve a particular target or goal.

  selecting

  repeating

  returning

  terminating

 5. Programs can use different types of loops to control the flow of a program: Fill in the blanks below.
_________ loops - repeat forever
______________loops - repeat a set amount of times
______________ loops - repeat until a condition is met

  if / condition-controlled / while-controlled

  infinite / count-controlled / condition-controlled

  infinite / for-while / while-if

  finite / condition-controlled / count-controlled

 6. On a desktop computer, the operating system has a program that keeps checks your USB ports to see if you have plugged in a device. Even after you have plugged in a device, it continues to check for new devices. This is an example of:

  an if statement within a looped nest

  a count controlled loop

  a condition controlled loop

  an infinite loop

 7. The count-controlled loop can be described as a ______ loop. The program repeats the action for a known number of times.

  WHILE

  FOR

  REPEAT ....UNTIL

  IF ELSE

 8. The following program moves the vehicle forward a distance set by the user:The count-controlled loop can be described as the ______________ structure. The program repeats the action for a known ____ number of iterations.
1 - Ask the user (˜How many centimetres do you want me to move forwards?™)
2 - Get a number and label it N
3 - Repeat (move forward) N times

  REPEAT / N

  For NEXT / N

  WHILE / 1

  IF ELSE / X

 9. A program is coded to help a robot avoid hazards. For example, if the robot vehicle is 3 cm from the edge of the table and it moves forwards 5 cm, it will fall off the edge. To stop this from happening, you might write a ______________ loop like this:
move forward
repeat until (touching table edge) 
_______________________________   loops can be used 
to add a high degree of intelligence to a computer system.

  condition-controlled

  selection-controlled

  if-controlled

  count-controlled

 10. In a while loop (condition controlled) the condition is at the start of the loop. What sort of loop is shown below?
#note this is not used in python, but shows the logic of the loop

count = 1
repeat
	print(count)
	count+=1
until count >3

  This is a for loop, as it includes for and next for the count

  This is a count controlled loop as the count starts at 1 and goes up to 3

  This is a while loop, as the condition is at the start

  a repeat ....until loop. The condition is at the end.