C#break、continue、return、goto

1.break

  break语句会使运行的程序立即退出包含在其中的最内层循环(结束此次循环且结束该循环控制体)或者switch语句

 1
 2 
 3 int i = 0;
 4 for(int j = 0 ; j < 100 ; j++)
 5 {  i++;
 6     if(i==50)break;
 7    Console.Write(i);
 8 }        

结果为:50

2.continue

  continue语句跳出本次循环,但不跳出循环体

 1 namespace @continue
 2 {
 3     class Program
 4     {
 5         public static void Main(string[] args)
 6         {
 7             for (int j = 0; j < 10; j++ )
 8             {
 9                 if (j == 5) continue;
10                 Console.Write(j);
11             }
12             Console.ReadKey();
13         }
14     }
15 }

结果为:12346789

3.return

  return语句用于指定函数返回的值,只能出现在函数体内;

4.goto

  goto语句将程序控制直接传递给标记语句

原文地址:https://www.cnblogs.com/gosun/p/5827489.html