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\n2. 5!=10\n3. 5!=20\n4. 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();
        }
    }
}

 

posted @ 2019-01-09 20:09  巨兽~墨菲特  阅读(105)  评论(0编辑  收藏  举报