Monday, July 25, 2011

Selection and repetition

Selection- Solving a problem often involves making a decision between two or more options. In an algorithm this process of making a decision is called selection.
Examples:
Moving through a set of traffic lights:
1. While driving along a road and come across a set of traffic lights.
2. If the green light is on, then continue driving as before.
3. If the yellow light is on, then begin to slow down and prepare to stop.
4. If the red light is on, then stop your vehicle immediately.

Deciding whether to take an umbrella to school.

1.Look outside of the house to determine the weather at that particular moment.
If:
- It is a sunny fine day, do not take an umbrella.
- It is a cloudy or rainy day take an umbrella with you.

Giving a student an A, B or C on their test.

Calculate the student's percentage of the score the student got on his test result.
If:
- the student got between 0 - 33.3% give them a C.
- the student got between 33.4 - 66.6% give them a B.
- the student got between 66.7 - 100% give them a A.

Repetition- Doing something again and again until you're satisfied, a set of repeated actions.


Examples:
 Filling a bucket with water.
1) Place bucket under tap.
2) Turn tap on.
3) Wait 0.5 minute:
If:
- 4/5 of bucket is filled close tap
- If 4/5 of bucket is not filled progress to step 4
4) Repeat step 3)until 4/5 of bucket is filled up.

Blowing up a balloon:
1. Take a balloon and blow air inside of it using your mouth.
2. Repeat blowing the balloon (blowing and stopping to gain air).
3. Stop blowing the balloon, press the open hole of the balloon to stop the air from escaping it and check if the balloon is the correct size you wanted.
4. Repeat until satisfied (until the balloon has been blown up to the correct size).
5. Tie a knot (or 2) at the opening of the balloon.







No comments:

Post a Comment