Page 72 - Touchcode_C6_Flipbook
P. 72

5                    LOOPS USING BLOCK CODING












                          Learning Outcomes

                        Introduction                                         Loop
                        Incrementing a Loop                                  Different Types of Loops

                       Nested Loop                                           Entry Criteria
                        Exit Criteria                                        Jump Statement





                  INTRODUCTION
                  You perform a variety of tasks daily, such as eating meals, taking a bath, watching TV, doing
                  homework, going to school, etc. You perform these tasks daily and repeat them at specific
                  intervals of time. There is a similar concept in programming, it is known as looping. In this
                  chapter you are going to learn more on looping.


                  LOOP
                  A loop is a construct which executes a block of 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.
                  If you do this with the same method, discussed above, it will become difficult to do so. In
                  such a scenario, you will use a loop to repeat the task as many times as you need.



                   70     Touchcode-VI
   67   68   69   70   71   72   73   74   75   76   77