Home / CSE MCQs / C#.Net MCQs :: C# Looping Statements

CSE MCQs :: C#.Net MCQs

  1. Select the output for the following set of code :

     static void Main(string[] args)
      {
          int i = 0, j = 0;
          l1: while (i < 2)
          {  
              i++;
              while (j < 3)
              {
                  Console.WriteLine("loop\n");
                  goto l1;
              }
           }
          Console.ReadLine();
      }
  2. A.
    loop is printed infinite times
    B.
    loop
    C.
    loop loop
    D.
    Compile time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. Select output for the following set of code :

    static void Main(string[] args)
     {
         int i, s = 0, a = 1, d;
         i = Convert.ToInt32(Console.ReadLine());
         do
         {
             d = i % (2 * 4);
             s = s + d * a;
         }while ((Convert.ToInt32(i = i / (2 * 4))) != 0 && (Convert.ToBoolean(Convert.ToInt32((a) = (a * 10)))));
         Console.WriteLine(s);
         Console.ReadLine();
     }
    enter i = 342.
  4. A.
    It finds binary equivalent of i
    B.
    It finds octal equivalent of i
    C.
    It finds sum of digits of i
    D.
    It finds reverse of i

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. Correct syntax for do while loop is :
  6. A.

    do;

       {

        statement;

       }while (condition);

    B.

    do(condition)

       {

         statement;

       }while;

    C.

    do

       {

         statement;

       }while (condition)

    D.

    do

       {

            statement;

       }while (condition);

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. Select the output for the following set of code:

    static void Main(string[] args)
     {
         int i, s = 0;
         for (i = 1; i <= 10; s = s + i, i++);
         {
             Console.WriteLine(s);
         }
         Console.ReadLine();
     }
  8. A.
    Code report error
    B.
    Code runs in infinite loop condition
    C.
    Code gives output as 0 1 3 6 10 15 21 28 36 45
    D.
    Code give output as 55

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. Which statement is correct among the mentioned statements?

    1. The for loop works faster than a while loop
    2. for( ; ; )implements an infinite loop
  10. A.
    Only 1 is correct
    B.
    Only 2 is correct
    C.
    Both 1 and 2 are correct
    D.
    Both 1 and 2 are incorrect

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What is the output for the following code ?

    static void Main(string[] args)
     {
         int a = 15, b = 10, c = 1;
         if (Convert.ToBoolean(a) && (b > c))
         {
             Console.WriteLine("cquestionbank");
         }
         else
         {
             break;
         }
     }
  12. A.
    cquestionbank
    B.
    It will print nothing
    C.
    Compile time error
    D.
    Run time error

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What is the output for the following code ?

    static void Main(string[] args)
      {  
          int a = 5;
          if (Convert.ToBoolean((.002f) -(0.1f)))
          Console.WriteLine("Sachin Tendulkar");
          else if (a == 5)
          Console.WriteLine("Rahul Dravid");
          else
          Console.WriteLine("Ms Dhoni");
          Console.ReadLine();
      }
  14. A.
    Rahul Dravid
    B.
    Sachin Tendulkar
    C.
    Ms Dhoni
    D.
    Warning : Unreachable Code

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. Select the output for the following set of code :

     static void Main(string[] args)
      {
          int  i = 9 , j = 7;
          switch (i - j + 3)
          {
          case 9: 7:
              j += 6;
              break;
          case 5:
              i -= 4;
              break;
          }
          Console.WriteLine(i + "\n" + j);
          Console.ReadLine();
      }
  16. A.
    5 7
    B.
    9 13
    C.
    Compile time error
    D.
    9 7

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. Select the output for the following set of Code:

     static void Main(string[] args)
      {
          int n, r;
          n = Convert.ToInt32(Console.ReadLine());
          while (n > 0)
          {
              r = n % 10;
              n = n / 10;
              Console.WriteLine(+r);
          }
          Console.ReadLine();
      }
     for n = 5432.
  18. A.
    3245
    B.
    2354
    C.
    2345
    D.
    5423

    View Answer

    Workspace

    Discuss Discuss in Forum