Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Development Algorithms and Language Constructs (sequence, selection and iteration) Higher Computing.

Similar presentations


Presentation on theme: "Software Development Algorithms and Language Constructs (sequence, selection and iteration) Higher Computing."— Presentation transcript:

1 Software Development Algorithms and Language Constructs (sequence, selection and iteration) Higher Computing

2 Lesson Aims and Objectives 1.Sequence This lesson will introduce you to algorithms for: 2. Selection 3. Iteration Most programming languages have constructs to support these algorithms

3 Algorithms Algorithms, which are just written- out sets of instructions to do something, consist of two things: 1. the actions that must be taken, and 2. the order they must be done in. The sequence of instructions Lights – Camera – Action not only tells a film crew what to do but also the order in which to do things. MIRRORS – SIGNAL - MANOEUVRE

4 Sequence Most simple algorithms found in everyday life are short and involve doing a series of things one after another. Buying a rail ticket 1. Select destination. 2. Select ticket type. 3. Insert correct money. 4. Take change. 5. Take ticket. The most common convention in programs and in everyday life is that we follow the instructions, starting at the top and working down the list, doing the instructions in the order given (this is a sequence of instructions)

5 Sequence Study this maze and make a plan for a race to the centre. During the race you cannot take your plan. Once you have worked out the route to the centre of the maze, you must memorise an algorithm that you must follow to get to the centre. Write an algorithm for the shortest route using the actions below: Enter the maze by the gate following the path ahead. Turn left following the path ahead. Turn right following the path ahead. Go straight across the junction following the path ahead. Stop at the cross.

6 If only... (Selection) Sequencing is not the only way instructions can be ordered You can alter the sequence of instructions depending on the situation. This is known as selection or branching. Putting on an airline oxygen mask 1. Place mask over your nose and mouth. 2. Secure with the elastic behind your head.

7 If only... (Single Branch Selection) Putting on an airline oxygen mask 1. secure your mask 2. if you are travelling with a child then 3. secure the mask of the child 4. endif 5. sit back The instructions given also consider situations other than the basic one. “if you are travelling with a child then secure your mask first, then secure the mask of your child Sequence– with child 1->2->3->4->5 Sequence – without child 1->2->4->5

8 If only... (Single Branch Selection) Deciding To Take A Break 1. if need a break then 2. pull into service station 3. park car 4. have coffee 5. use slip road onto motorway 6. end if 7. continue journey A motorway has a service station. A driver, drives down the motorway. On seeing the sign for the Service Station, she asks herself the question “Do I need a break”. If the answer is yes, she pulls in and has a coffee. On finishing the coffee she pulls back onto the motorway, using the exit slip road. If the answer is no, she just drives on and performs no action. In either case she arrives at the same point to continue her journey.

9 Play it Again Sam (Fixed Iteration) Writing Lines 1. for counter = 1 to 100 do 2. write punishment line 3. next counter At school as a punishment you might have to write lines: writing the same thing over and over again. “Write out 100 times, ‘I must not throw chewing gum at the teacher’ ” “Write out 30 times, ‘I must not break up my desk and pass the bits out of the window behind the teacher’s back’ ”, With fixed iteration we know in advance the number of times an instruction needs to be repeated

10 Play it Again Sam (Conditional Iteration) Suppose you wish to read all the books on your bookshelf. This is a situation where you are doing a similar thing over and over again. It should therefore be possible to describe it by giving the instructions to be repeated and the instructions on when to stop. The repetitive task (the body) is: 1. Pick a book that you have not read. 2. Read the book. 3. Put the book back. Termination Condition Continue, provided there are books on the shelf you have not read

11 Play it Again Sam (Conditional Iteration) Reading all books on my bookshelf 1. Do 2. Pick a book that you have not read. 3. Read the book. 4. Put the book back 5. Loop while books on shelf I have not read

12 Activities 1.Review this PowerPoint. di 2. Complete the sheet on my web page. Save as directed.


Download ppt "Software Development Algorithms and Language Constructs (sequence, selection and iteration) Higher Computing."

Similar presentations


Ads by Google