Sunday, February 21, 2010

GOTO statement in C#

GOTO statement is a very useful statement when the flow of control is very narrow. Following is the syntax sample for this statement.

Sample Code:

if (k==12)

{

goto Yes;

}

Yes:

Console.WriteLine("Same”);

Done:

Console.WriteLine("Search Completed”);

In the above sequence of code, if K is equal to 12 then the control would jump to “Yes” line and start executing them.  Point to note is the that even if the condition is satisfied, the Done block would also be processed because GOTO statement is only for transferring control and the blocks like “Yes” and “Done” acts merely as line number/names.

No comments:

Post a Comment