Page 67 - Computer Genius Class 07
P. 67

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.
                    Se uence o  programming re ects logical thin ing.
                 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 a o e routine may  ary  rom person to person  ut  or a specific person this might  e 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    nput first num er   um1           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 a ter that add  um 1 and  um 2  the program  ill not gi e the re uired result or gi e 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


                                                                                Advanced MakeCode Arcade      65
   62   63   64   65   66   67   68   69   70   71   72