Page 74 - Digicode_AI_class_8
P. 74
What is a Sequence?
A sequence in programming is an ordered set of instructions or tasks. In case, if you follow the
wrong order, then the task cannot be achieved, or you may get the unexpected results.
Example of sequence is an algorithm, which is a detailed step-by-step process that needs to be
followed in order to complete a task or to solve a problem.
Benefits of using Sequences in coding:
• Our manner of thinking can be easily replicated in sequence programming.
• Sequence of programming reflects logical thinking.
Example: Algorithm of your daily routine
You daily routine is a series of actions which you do every day as follows.
Step 1 Wake up Step 7 Get back home
Step 2 Take a shower Step 8 Watch TV
Step 3 Have breakfast Step 9 Do homework
Step 4 Go to school Step 10 Play
Step 5 Attend classes Step 11 Have dinner
Step 6 Have lunch Step 12 Go to sleep
The above routine may vary from person to person but for a specific person this might be the routine.
An algorithm is a process or set of rules which need to be followed to solve the given problem.
Example: Algorithm to calculate the sum of two numbers.
Step 1 Input first number (Num1) Step 3 Sum = Num1 + Num2
Step 2 Input second number (Num2) Step 4 Print Sum
In the above example, if we swap Step 3 and Step 4, i.e. you are instructing computer to Print Sum
first and after that add Num 1 and Num 2; the program will not give the required result or give an
error. This is called a bug.
Sequencing with Loops and Conditions
While writing an algorithm,three basic building blocks are used, sequencing, selection and iteration.
Building blocks help us to uncover the solution to a complex problem which can be understood and
implemented by others using programming.
To understand the concept of sequencing in programming.
Let’s take an example of sequence:
Example: Algorithm to swap two numbers.
Step 1 READ num1, num2 Step 4 num2 = temp
Step 2 temp = num1 Step 5 PRINT num1, num2
Step 3 num1 = num2 Step 6 Stop
72 DigiCode AI-VIII

