一、C# break语句

break语句用于终止它后面的所有循环语句,使控制流程跳转到break语句所在层的外面,以便结束本层的所有循环。如果有多个循环语句进行嵌套,break语句则会跳到它所在层的外层。

语法格式如下:

break;二、示例
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            // C# break语句-www.baike369.com
            for (int i = 1; i <= 10; i++)
            {
                if (i == 3)
                    break;
                Console.WriteLine(i);
            }
            Console.WriteLine("break语句跳转到这里!");
            Console.ReadLine();
        }
    }
}

运行结果:
 
1
2
break语句跳转到这里!

 

相关文章:

  • 2021-05-07
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2021-08-01
  • 2021-12-21
  • 2021-10-12
猜你喜欢
  • 2022-12-23
  • 2021-11-26
  • 2021-05-25
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
相关资源
相似解决方案