目录

break 声明

break语句用于将控件从构造中取出。 在循环中使用break会导致程序退出循环。 以下是break语句的示例。

例子 (Example)

void main() { 
   var i = 1; 
   while(i<=10) { 
      if (i % 5 == 0) { 
         print("The first multiple of 5  between 1 and 10 is : ${i}"); 
         break ;    
         //exit the loop if the first multiple is found 
      } 
      i++; 
   }
}  

上面的代码打印出1到10之间的数字范围的5的第一个倍数。

如果发现一个数字可被5整除,则if结构强制控件使用break语句退出循环。 成功执行上述代码后,将显示以下output

The first multiple of 5 between 1 and 10 is: 5 
↑回到顶部↑
WIKI教程 @2018