C# Loop MCQs

Question 1: What will be the output of the following program?

int i = 0;

for(;;)
{
    if (i < 5)
            Console.Write(i);
    else
        break;
	i++;
}

Question 2: What will be the output of the following program?

for (double d = 1.01D; d < 1.05; d+= 0.01D)
{
    Console.Write("{0}, ", d);
}

Question 3: What will be the output of the following program?

public static void Main()
{
	while (ProcessMessage());
}
	
static bool ProcessMessage() {
	Console.Write("Hello");
	return false;
}

Question 4: What will be the output of the following program?

int i = 15;

for( ; ; )
{
    Console.Write("{0} ",i); 
    if (i >= -5)
        i -= 5; 
    else 
        break;
}

Question 5: What will be the output of the following program?:

public static void Main(string[] args)
{
	string str = "Hello";
		
    for(int i = 0; i<str.Length; i++)
        Console.WriteLine(str[i]);
}

Question 6: What will be the output of the following program?

static void Main()
{
    foreach (int number in GetNumbers())
    {
        Console.Write(number.ToString() + " ");
    }
}

public static System.Collections.IEnumerable GetNumbers()
{
    yield return 10;
    yield return 20;
    yield return 30;
} 

Question 7: What will be the output of the following program?

static void Main()
{
    foreach (int number in GetNumbers())
    {
        // do nothing
    }
}

public static System.Collections.IEnumerable GetNumbers()
{
    Console.Write("yield-1 ");
    yield return 10;

    Console.Write("yield-2 ");
    yield return 20;

    Console.Write("yield-3");
    yield return 30;
}