Page 104 - Computer Genius Class 06
P. 104
Apply Loops and Conditionals with Sequencing
Let us learn how to use loops and conditional with the help of sequencing.
Selection
Selection can be described as making a choice based on a criteria. Think of it as IF this THEN that.
election is an important part o coding. t helps us to choose different paths and react to situations.
Example: ‘Is it raining today?”
If the answer to the question is true, then the algorithm follows one path.
If the answer is false, the algorithm follows a different path.
Iteration
To run a loc o code specific num er o times iteration is used. teration can e defined as doing
or repeating the same tas again and again until the specified condition is met. teration is repeating
situations.
Example: n a car race a car must go around a trac fi e times. The car ill eep going around the trac
repeatedly until it completes fi e laps. nce it is done it ill e it the trac .
Now let’s combine all the three building blocks of an algorithm: sequencing, selection, and iteration.
Let’s look at our cup of tea task with sequence, selection and iteration. We have the same number
o steps ut our process has ecome more precise ho long to stir or e cient e don t fill the
kettle if it has water in it already) and we have choice (milk or no milk).
Step 1 IF the kettle has no water THEN fill the kettle with water
Step 2 Turn the kettle on
Step 3 Put tea bag in the cup
Step 4 Pour hot water into the cup
Step 5 Remove tea bag
Step 6 IF you take milk THEN add milk
Step 7 If you take sugar THEN add sugar. Stir until the milk has been mixed into the tea
In real life, complex algorithms can have hundreds of steps in a sequence and there are certain activities
in the sequence which are repeated. We can reduce the number of steps of the sequence by using a loop
along with certain conditions to check when the loop should stop.
What is a Bug?
ug is an une pected pro lem in your program. ou ollo a defined se uence to rite a program
rom hich you e pect to return a specific output. ny change in the e pected and actual output o
the program is said to be the result of a bug.
So, we can say that bug is a general term which is used to describe any unexpected problem with
hardware or software.
Example: Suppose you are going out for a family picnic. You are ready to go, but you notice that
the tyre of the car is puncture, due to which your picnic will get delayed for few hours or you need
to postpone it or some other day. s first you need to repair the tyre. o this puncture in the tyre
of the car can be termed as a ‘bug’ in programming.
102 Computer Genius-VI

