From the C# ECMA Specification:
class Test
{
static void Main(string[] args)
{
string[,] table = {
{"red", "blue", "green"},
{"Monday", "Wednesday", "Friday"}
};
foreach (string str in args)
{
int row, colm;
for (row = 0; row <= 1; ++row)
for (colm = 0; colm <= 2; ++colm)
if (str == table[row, colm])
goto done;
Console.WriteLine("{0} not found", str);
continue;
done:
Console.WriteLine("Found {0} at [{1}][{2}]", str, row, colm);
}
}
}
In the example above, there are several nested for loops. Each of these has
a local scope that includes all code inside the loop. goto statements are
typically used to break out of nested loops, and in the example above, the
goto statement exits the innermost loop and in fact, its' target is outside
the topmost for loop. This makes the code simpler than using a break
statement in all 3 loops. However, you cannot use a goto statement to ENTER
a loop that is nested inside the scope in which the goto statement resides.
For example, you could not use a goto statement in the outermost loop to
enter any of its' nested loops.
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
"AA2e72E" <AA*****@discussions.microsoft.comwrote in message
news:E5**********************************@microsof t.com...
Could someone give me a simple example of nested scope in C#, please?
I've searched Google for this but have not come up with anything that
makes
it clear. I am looking at the ECMA guide and trying to understand Goto in
this contect.
PS: This is not homework.