Vidyalelo
C# Programming · all questions

Control Flow Statements in C Sharp
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

92

Questions

3/5

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i = 2, j = 4;
    switch (i + j * 2)
    {
    case 1 :
    case 2 :
        Console.WriteLine("1 and 2");
        break;
    case 3 to 10:
        Console.WriteLine("3 to 10");
        break;
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

For the incomplete C# program below, which of the C# code fragment will not result in an infinite loop?
static void Main(string[] args)
{
    int i = 1234 ,j = 0;
     /*ADD CODE HERE */
    Console.WriteLine(j);
}

Options are not available for this question.

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int x = 0;  
    while (x < 20)
    {
        while (x < 10)
        {
            if (x % 2 == 0)
            {
                Console.WriteLine(x);
            }
            x++;
        }
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    float i = 1.0f, j = 0.05f;
    do
    {
        Console.WriteLine(i++ - ++j);
    }while (i < 2.0f && j <= 2.0f);
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    Console.WriteLine("HI");
    continue;
    Console.WriteLine("Hello");
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# 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();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
{
    int i;
    Console.WriteLine("Hi");
    for (i = 1; i <= 10; i++)
        Program.Main(args);
    Console.ReadLine();
}

Select an option to see the answer and solution.

Which statement is correct among the mentioned statements?
i. The for loop works faster than a while loop
ii. for( ; ; )implements an infinite loop

Select an option to see the answer and solution.

Which of the following is not infinite loop?

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i = -10;
    for ( ;Convert.ToBoolean(Convert.ToInt32(i)) ;Console.WriteLine(i++)) ;
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i = 2, k = 3;
    switch (i - k)
    {
    case -1:
        ++i;
        ++k;
        break;
    case 2:
        --i;
        ++k;
        break;
    default:
        i += 3;
        k += i;
        break;
    }
    Console.WriteLine(i + "\n" + k);
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i = 1, j;
    do
    {
        for (j = 1; ; j++)
        {
            if (j > 2)
                break;
            if (i == j)
                continue;
            Console.WriteLine(i + " " + j);
        }
        i++;
    } while (i < 3);
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i;
    Console.WriteLine("enter value of i:");
    i = Convert.ToInt32(Console.ReadLine());
    if ( i % 2 == 0)
        goto even:
    else
    {
        Console.WriteLine("number is odd:");
        Console.ReadLine();
    }
    even:
    Console.WriteLine("number is even:");
    Console.ReadLine();
}
for i = 4.

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i = 2, j = 3, k = 4;
    switch (i + j - k)
    {
    case 0: case 2: case 4:
        ++i;
        k += j;
        break;
    case 1: case 3: case 5 :
        --i;
        k -= j;
        break;
    default:
        i += j;
        break;
    }
    Console.WriteLine(i + "\n" + j + "\n" + k);
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i = 1, j = 2, k = 3;
    do
    {
        Console.WriteLine((Convert.ToBoolean(Convert.ToInt32(i++))) 
        && (Convert.ToBoolean(Convert.ToInt32(++j))));
    }while (i <= 3);
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    char ch = Convert.ToChar('a' | 'b' | 'c');
    switch (ch)
    {
    case 'A':
    case 'a':
        Console.WriteLine("case A|case a");
        break;
    case 'B':
    case 'b':
        Console.WriteLine("case B|case b");
        break;
    case 'C':
    case 'c':
    case 'D':
    case 'd':
        Console.WriteLine("case D|case d");
        break;
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    float s = 0.1f;
    while (s <= 0.5f)
    {
        ++s;
        Console.WriteLine(s);
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int x = 10;
    do
    {
        Console.WriteLine( x++);
    }
    while(Convert.ToBoolean(5) && Convert.ToBoolean(4) && Convert.ToBoolean(3) 
    && Convert.ToBoolean(2) && Convert.ToBoolean(1) && Convert.ToBoolean(0));    
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i;
    Console.WriteLine("enter value of i:");
    i = Convert.ToInt32(Console.ReadLine());
    if (i < 7)
    {
        i++;
        continue;
    }
    Console.WriteLine("final value of i:" +i);
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int i = 0;
    if (i == 0)
    {
        goto label;
    }
    label: Console.WriteLine("HI...");
    Console.ReadLine();
}

Select an option to see the answer and solution.