Goto (C # quiz)
GotoSimply move the program control directly to the standards.
Zookeeper
GotoThe common usage is to shift the cursor to a specific switch-case tag orSwitchThe identifier set in the example.
GotoThe statement is also useful for jumping out of the nested loop.
Example
The following example shows how to useGoto.
Compile the program Program
// Statements_goto_switch.csusing system; Class switchtest {static void main () {console. writeline ("coffee sizes: 1 = small 2 = medium 3 = large"); console. write ("Please enter your selection:"); string S = console. readline (); int n = int. parse (s); int cost = 0; Switch (n) {Case 1: cost + = 25; break; Case 2: cost + = 25; goto case 1; Case 3: cost + = 50; goto case 1; default: console. writeline ("Invalid selection. "); break;} If (Cost! = 0) {console. writeline ("Please insert {0} cents.", cost);} console. writeline ("Thank you for your business .");}}
Ingress
2
Output in the example
Coffee sizes: 1 = small 2 = medium 3 = largeplease enter your selection: 2 Please insert 50 cents. Thank you for your business.
The following example shows how to useGotoIn the middle nest.
Compile the program Program
// statements_goto.cs // nested search loopsusing system; public class gototest1 {static void main () {int x = 200, y = 4; int COUNT = 0; string [,] array = new string [x, y]; // initialize the array: for (INT I = 0; I