Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

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();
}

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();
}
a) 12
b) 11
c) Compile time error
d) 13

Answer: c
Explanation: ‘Continue’ loop cannot be used within ‘if’ loop. replace while with if(i < 7).
Output: Compile time error.

Join The Discussion