c# 之入门简介1

goto  语句

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _5._12跳转
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 0;
            Console.WriteLine("5的阶乘等于几?请选择:");
            Console.WriteLine("1. 5!=5
2. 5!=10
3. 5!=20
4. 5!=60");
        error:
            {
                a++;
                if (a > 1) Console.WriteLine("you are wrong!");
            }
            int option = int.Parse(Console.ReadLine());
            switch (option)
            {
                case 1:
                case 2:
                case 3:goto error;
                case 4:goto right;
                default:
                    Console.WriteLine("请重新选择。");
                    goto end;            }
        right:
            {
                Console.WriteLine("ok!!!!");
            }
        end:


            Console.ReadKey();
        }
    }
}
原文地址:https://www.cnblogs.com/Mengchangxin/p/10246610.html