Break and Continue

来源:互联网 发布:for mac软件 编辑:程序博客网 时间:2024/06/05 17:33
public class BreakAndContinue {/** * 这个例子同样是在java编程思想中摘抄的~ * 对于循环总的break 大多数人都还是分得清楚的,但是对于continue就则显得有点模糊,知道什么情况,但是别人问及的时候 * 却有点说不出。 * 下面是里面的说法: * break  quits the loop without executing the rest of the statements in the loop * break 结束循环,不再执行循环中剩下的语句 * continue stops the execution of the current iteration and goes back to the begginning of the loop to begin the next iteration * continue 停止当前的迭代,然后返回到循环的开始,开始下一个迭代 */public static void main(String[] args) {for( int i=0;i<100;i++){if(i==70){break;//当条件成立的时候,退出循环液就是说后边的输出语句中不可能有比70大的}if(i%10!=0){continue;//当遇到 i%10!=0的情况,将回到循环的前面,开始下一个的迭代}System.out.print(i+"  ");}}}