I have just been asked this question in an interview: "What can't be done in a nested loop in C#?" and I was stumped!
Is there a correct answer to this question? Or is it meant to stump people?
I have just been asked this question in an interview: "What can't be done in a nested loop in C#?" and I was stumped!
Is there a correct answer to this question? Or is it meant to stump people?
I am almost certain that the interviewer was talking about breaking out of the outer loop without using goto
statement.
This is, indeed, a problem that has been successfully solved in other similar languages, such as Java.
This Q&A provides more information on the problem.
Cannot guess what was expected answer but one comes to mind. It is mentioned in C# specs chapter 3.7 Scopes
within a nested block it is not possible to declare a local variable with the same name as a local variable in an enclosing block