Page 101 - Computer Genius Class 06
P. 101

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.

                 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   Input first number (Num1)

                 Step 2   Input second number (Num2)
                 Step 3   Sum = Num1 + 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. We will discuss the bug in detail later in the chapter.

                 Loop

                   loop is a construct  hich e ecutes a  loc  o  code multiple times until a specific condition is met.

                 Benefits:
                   Reduces lines of code

                   Code becomes easier to understand
                 Consider an example:
                 Suppose you want to print alphabets from a to d on the screen. You can do this by printing the values
                 a, b, c and d by writing four lines of code like:

                 Program Start                Output:
                 Print a                      a
                 Print b                      b
                 Print c                      c
                 Print d                      d

                 Program End
                 Doing this was easy. What if, you need to print numbers in incremental order from 1 to 1000.
                    you do this  ith the same method  discussed a o e  it  ill  ecome di cult to do so.  n such a
                 scenario, you will use a loop to repeat the task as many times as you need.






                                                                                  More on MakeCode Arcade     99
   96   97   98   99   100   101   102   103   104   105   106