Page 216 - CA_Blue( J )_Class10
P. 216

What will be the final value of the sum after executing the above code?
                     a.  60                                         b.  75
                     c.  90                                         d.  0
                  4.  Consider the following code:
                     int i, j=0, sum=0;
                     for(i = 1; i <= 5; i++)
                          for(j = 2; j <=5; j++)
                               break;
                     sum = sum + j;
                     Which of the following is the final value of the sum?
                     a.  1                                          b.  2
                     c.  50                                         d.  60
                  5.  A loop inside another loop is called ………………….
                     a.   Nested loop                               b.   Merged loop
                     c.   Combined loop                             d.   Infinite loop

                Answers
                1. c       2. a     3. b      4. b     5. a


              B.  Fill in the blanks.
                  1.  If a for loop is used within another for loop, then it is called a ………………… loop.
                  2.  The ………………… statement is used for exiting the loop.
                  3.  The ………………… statement is used for executing the next iteration of the loop without executing the rest of the loop statements.

                Answers
                1. nested for      2. break      3. continue

              C.  Answer the following questions:

                  1.  Find the error.
                    int i, j;
                    for(i=1; i<=3, i++)
                    {  for(j=1; i<=i; j++)
                    {  System.out.println(k);         }
                    }
                Ans.  There are two mistakes:
                     a.     Instead of “,” it will be “;” after the test condition in the outer loop
                     b.  There is no k variable
                  2.  Predict the output:
                    int a=2;
                            while(a<4)
                            {   int b=1;
                                while(b>0)
                                {    System.out.println(a + b);
                                    b--;
                                }
                                a=a+2;
                            }
                Ans.  3
                                                      a           b           Output
                                                      2           1              3
                                                                  0>0x
                                                      4<4x


                214214  Touchpad Computer Applications-X
   211   212   213   214   215   216   217   218   219   220   221