c# 之入門簡介1
阿新 • • 發佈:2019-01-09
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(); } } }