Page 265 - CA_Blue( J )_Class9
P. 265

public static void main(String s[])
                           {
                               int sum = 56;
                                    for(int i = 3; i <= 6; i++ )
                               {
                                   for(int j = 8; j <= 10; j++ )
                                   {
                                     sum += ( i * j);
                                   }
                               }
                               System.out.println("sum = " + sum);
                           }
                       }
                        a.   sum = 562                                 b.   sum = 542
                        c.   Logical error                             d.   sum = 96
                    4.   Consider the following code segment.

                       int k = 0;
                       int m = 5
                       int n = m;
                       while (k < n)
                       {
                        k++;
                        n--;
                       }
                       System.out.println(k + n);
                       What is the output when the segment executes?
                        a.   Logical error                             b.   Syntax error
                        c.   5                                         d.   None of these

                    5.   A break statement  inside a Loop like while, for and do while causes the program execution ………………… the loop.
                        a.   Exit                                      b.   Continuation with next iteration
                        c.  Never exit                                 d.   Jump with next iteration

                 B.  Fill in the blanks.
                    1.   A loop within a loop is called ………………… .

                    2.   …………………  statement is used to terminate a loop.
                    3.   Continue statement …………………  the execution of a loop.
                    4.   …………………  loop within a do-while loop is known as a nested do-while loop.

                 C.  Answer the following questions.
                    1.   Differentiate between the following
                        a.  Nested for and Nested Do-while
                        b.  Break and Continue
                    2.   Define Nested Loop.
                    3.   Write the syntax of a nested while loop.
                    4.   Write a program to demonstrate the use of a break statement in a nested while loop.







                                                                                                   Nested Loop   263
   260   261   262   263   264   265   266   267   268   269   270