C# Programming - Control Instructions - Discussion

Discussion :: Control Instructions - General Questions (Q.No.19)

19. 

What will be the output of the code snippet given below?

int i;
for(i = 0; i<=10; i++)
{
    if(i == 4)
    {
        Console.Write(i + " "); continue;
    }
    else if (i != 4)
        Console.Write(i + " "); else
    break;
}

[A]. 1 2 3 4 5 6 7 8 9 10
[B]. 1 2 3 4
[C]. 0 1 2 3 4 5 6 7 8 9 10
[D]. 4 5 6 7 8 9 10
[E]. 4

Answer: Option C

Explanation:

No answer description available for this question.

Charu said: (Jul 14, 2011)  
Explain this solution.

Naresh said: (Dec 7, 2011)  
Nothing special in this, when i not equal to 4, lower if will execute and later after printing 4 in upper if again it will execute lower if. Hence 0 ot 10 will print.

Zubair Khan said: (Apr 9, 2016)  
When i! = 0 then it will print 0, 1, 3.

When its true it prints 4.

Again if false then prints 5, 6, 7, 8, 9, 10.

Stephanie said: (Apr 9, 2017)  
Why use the break?

Explain clearly.

Div said: (Jun 27, 2017)  
For exit the loop @Stephanie.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.