Page 238 - CA_Blue( J )_Class9
P. 238

10


                                                                             NESTED LOOP
















                            Learning Objectives


                      10.1 Nested for Loop                             10.2 Nested while Loop
                      10.3 Nested do-while Loop                        10.4 Using break Statement in Nested Loop
                      10.5 Using continue Statement in Nested Loop






                  In the previous chapter, we have learnt about loops and their          Definition
                  uses. Loops are quite helpful in creating complex programs.
                  They helps us to reduce the lines of code, which helps us to   A Nested loop is  a loop  inside another loop,
                  create lighter codes that use memory efficiently. We can also   where the inner loop executes completely for
                  use a loop within another loop creating a nested loop. There   each iteration of the outer loop.
                  are different types of nested loops.




                                                          Types of Nested Loop





                                Nested for loop             Nested while loop          Nested do-while loop


                                           Structure of a nested loop:

                                              Outer loop structure statement
                                              {
                                                  Inner loop structure statement
                                                  {
                                                      Statements inside inner loop
                                                  }
                                                  Statements inside outer loop
                                              }

                  Let us study the different types of nested loops in detail.



                   236    Touchpad Computer Applications-IX
   233   234   235   236   237   238   239   240   241   242   243