美文网首页
029_goto和return来跳出循环。

029_goto和return来跳出循环。

作者: 立秋i | 来源:发表于2018-03-30 23:34 被阅读0次

    namespace _029_goto和return来跳出循环 {

        class Program {

            static void Main(string[] args) {

                //while (true)

                //{

                //    int num = Convert.ToInt32(Console.ReadLine());

                //    if (num == 0)

                //    {

                //        goto myLabel;

                //    }

                //}

                //myLabel:

                //Console.WriteLine("跳出循环了");

                while (true)

                {

                    int num = Convert.ToInt32(Console.ReadLine());

                    if (num == 0)

                    {

                        return;//用来终止方法的,表示方法运行结束,剩余的代码不执行了

                    }

                }

                Console.WriteLine("跳出循环了");

                Console.ReadKey();

            }

        }

    }

    相关文章

      网友评论

          本文标题:029_goto和return来跳出循环。

          本文链接:https://www.haomeiwen.com/subject/grimcftx.html