C# goto
Statement
The goto statement
in c# is used to transfer control to a predefined label statement, it can be
used to skip execution in a loop on reaching a condition, if a goto statement is reached then the code execution is transferred
to the location where the goto label
is pointing to.
for (int i
= 1; i <= 10; i++)
{
if (i == 5)
{
goto
SkipLoop;
}
//
Response.Write(i.ToString() + "<br>");
}
//
SkipLoop:
Response.Write("Statement after the for Loop");
In the above example when i values is equal to 5 the goto statement is executed and code execution is transferred
to SkipLoop label statement, the output in this case will be
1
2
3
4
Statement after the for Loop
That’s it, we have evaluated the use of the goto statement.
2
3
4
Statement after the for Loop
That’s it, we have evaluated the use of the goto statement.
Related Post
No comments:
Post a Comment