Page 77 - CloudGPT_C8_Flipbook
P. 77

display 'I want to play'
                        increase the value of a by 1

                 Program End
                                                                                                      Subject Enrichment
                   Example 2: To print all the odd numbers from a list using for loop.


                 Pseudocode:

                 Program Start
                 list1 = [12, 25, 8, 50, 75, 30]
                 for a in list1
                        if a % 2!= 0
                        print(a, end = ' ')
                        increase the value of a by 1
                 Program End                                                                          Subject Enrichment


                   Example 3: To print all the even numbers from the given list by using 'for' loop.


                 Pseudocode:
                 Program Start

                 list2 = [14, 25, 8, 50, 75, 30]
                 for a in list2
                        if a % 2 == 0

                        print(a, end = ' ')
                        increase the value of a by 1
                 Program End

                   Coding           uiz   01                                                           Critical Thinking



                    Fill in the blanks.

                    a.  A  ............... loop  statement repeatedly  executes a statement as long  as the
                        condition remains true.

                    b.  A  ............... loop executes for a specific number of times.




                 NESTED LOOP
                 Any loop in a program may contain another loop inside it. When there is a loop inside another

                 loop, it is called nested loop. A nested loop is helpful in case if you are working on multiple
                 conditions. There is no restriction on the number of loops to be nested inside a loop.

                                                                                     Loops Using Block Coding    75
   72   73   74   75   76   77   78   79   80   81   82