Goto (C # Testing

Source: Internet
Author: User
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 
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.