Java中关键字continue、break和return的区别
版权声明:本文为博主原创文章,未经博主允许不得转载。 http://blog.csdn.net/shineflowers/article/details/41747149
Java中关键字continue、break和return的区别:
continue:跳出本次循环继续下一次循环
break: 跳出循环体,继续执行循环外的函数体
return: 跳出整个函数体,函数体后面的部分不再执行
有代码才有真相:
[java] view plain copy
- <span style="font-family:SimSun;font-size:14px;"><span style="font-family:SimSun;font-size:14px;">public class JavaBese {
- public static void main (String[] args) {
- int j = 3;
- for (int i = 0; i < 5; i++) {
- if (i == j) {
- continue;
- }
- System.out.println("i = " + i);
- }
- System.out.pintln("循环结束");
- }
- }</span></span>
打印结果为:
i = 0
i = 1
i = 2
i = 4
循环结束
如果是break,打印结果为:
i = 0
i = 1
i = 2
循环结束
如果是return, 打印结果为:
i = 0
i = 1
i = 2
以上是 Java中关键字continue、break和return的区别 的全部内容, 来源链接: utcz.com/z/391697.html