1. Question: What will be the output of the following code?
    int i = 0;
    while (i < 3)
    {
        Console.WriteLine(i);
        i++;
    }

    A
    0 1 2

    B
    1 2 3

    C
    0 1 2 3

    D
    0 1

    Note: The loop runs while i is less than 3, printing 0, 1, and 2.
    1. Report
  2. Question: What will happen if the condition in a while loop is always true?

    A
    The loop will execute once.

    B
    The loop will execute infinitely.

    C
    The loop will never execute.

    D
    It will throw an exception.

    Note: An always-true condition leads to an infinite loop unless broken by another condition or a break statement.
    1. Report
  3. Question: Which statement is used to handle multiple conditions in C#?

    A
    if-else

    B
    switch

    C
    Both

    D
    None

    Note: Both if-else and switch statements can be used to handle multiple conditions.
    1. Report
  4. Question: What will the following code output?
    int x = 5;
    if (x < 10)
        Console.WriteLine("Less than 10");
    else if (x < 20)
        Console.WriteLine("Less than 20");
    else
        Console.WriteLine("20 or more");

    A
    Less than 10

    B
    Less than 20

    C
    20 or more

    D
    No output

    Note: The first condition x < 10 is true, so that block executes.
    1. Report
  5. Question: What will the following code print?
    int i = 0;
    do
    {
        Console.WriteLine(i);
        i++;
    } while (i < 3);

    A
    0 1 2

    B
    1 2 3

    C
    0 1 2 3

    D
    0 1

    Note: The do-while loop executes the body at least once before checking the condition.
    1. Report
  6. Question: Which of the following correctly represents a nested if statement?

    A
    if (x > 0) if (x < 10) { }

    B
    if (x > 0) { if (x < 10) { } }

    C
    Both

    D
    None

    Note: Both representations are valid nested if statements.
    1. Report
  7. Question: What does the following code do?
    for (int i = 0; i < 5; i++)
    {
        if (i == 3) break;
        Console.WriteLine(i);
    }

    A
    Prints 0 1 2 3

    B
    Prints 0 1 2

    C
    Prints 0 1 2 3 4

    D
    Prints nothing

    Note: Prints nothing
    1. Report
  8. Question: What will be the output of the following code?
    int x = 0;
    while (x < 3)
    {
        Console.WriteLine(x);
        x += 1;
    }

    A
    0 1 2

    B
    0 1 2 3

    C
    1 2 3

    D
    0 1

    Note: The loop runs while x is less than 3, printing 0, 1, and 2.
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd