C # Goto Learning

Source: Internet
Author: User

The following code:

            int 5 ;             Goto B; // A goto statement is used to control the location            of a tag. a++;            B:console.writeline (a);            Console.readkey ();

The output is: 5, execute goto, skip execution a++;

Goto and return jump out of the loop difference:

             while(true)            {                intnum =Convert.ToInt32 (Console.ReadLine ()); if(num = =0)                {                    GotoC; }} c:console.writeline ("jump out of the loop");  while(true)            {                intnum =Convert.ToInt32 (Console.ReadLine ()); if(num = =0)                {                    return;//used to terminate the method, indicating that the method is running and that the remaining code does not execute the}} Console.WriteLine ("jump out of the loop"); Console.readkey ();

Comprehensive:

1>goto

The statement can jump to any place where the label is located to continue execution, it is worth noting that the label must be in the same function as the Goto statement, cannot cross the function body.

2>return

If a return statement is encountered in the program, the code exits the function's execution, returns to the function's call, and, if it is the main () function, ends the entire program's run.

C # Goto Learning

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.