Page 75 - CloudGPT_C8_Flipbook
P. 75

DIFFERENT TYPES OF LOOPS
                 Loop runs a statement or group of statements multiple times till the given condition is true.

                 There are different types loops. Although they perform the same task, but their working is
                 different. Let us take a look at the types of loop.

                 Different types of loops are:
                 1.  While Loop

                 2.  For Loop

                 While Loop/Conditional loop
                 While Loop executes a statement or group of statements till a given condition is true. Once

                 the condition is false, the loop is terminated.
                                                                                                      Subject Enrichment
                   Example 1: To print number from 1 to 10.


                 Condition: Till the time a is less than 10, the body of the while loop will run.

                 Decision: Have we reached number 10, if yes stop the loop.

                 Pseudocode:

                 Program Start
                 set a to 0
                 while a is less than 10
                        increase the value of a by 1

                        display a
                 Program End
                                                                                                      Subject Enrichment

                   Example 2: To print a statement five times by using a while loop.


                 Condition: Till the time the test expression remains true, the body of the while loop will run.

                 Decision: Have we printed the statement five times or not?
                 Pseudocode:

                 Program Start
                 set a to 0
                 while a is less that 5

                        increase the value of a by 1
                        display Hello World
                 Program End




                                                                                     Loops Using Block Coding    73
   70   71   72   73   74   75   76   77   78   79   80