The break and continue keywords are used to stop either the entire loop
(break) or just the current iteration (continue).
public class ForLoop {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
System.out.println("Inside loop, i = "+i);
if (i == 3) {
System.out.println("if is true: i == 3");
continue;
// compile error: says it's unreachable
// System.out.println("after the continue statement");
}
// more loop code, that won't be reached when the above if test is true
System.out.println("after the if statement, still inside loop");
}
System.out.println("out of loop");
}
}
Output:
Inside loop, i = 0
after the if statement, still inside loop
Inside loop, i = 1
after the if statement, still inside loop
Inside loop, i = 2
after the if statement, still inside loop
Inside loop, i = 3
if is true: i == 3
Inside loop, i = 4
after the if statement, still inside loop
out of loop
public class ForLoop {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
System.out.println("Inside loop, i = "+i);
if (i == 3) {
System.out.println("if is true: i == 3");
break;
// compile error: says it's unreachable
// System.out.println("after the continue statement");
}
// more loop code, that won't be reached when the above if test is true
System.out.println("after the if statement, still inside loop");
}
System.out.println("out of loop");
}
}
Output:
Inside loop, i = 0
after the if statement, still inside loop
Inside loop, i = 1
after the if statement, still inside loop
Inside loop, i = 2
after the if statement, still inside loop
Inside loop, i = 3
if is true: i == 3
out of loop
分享到:
相关推荐
continue break 循环.py
break与continue语句 中断语句 break与continue语句 1 了解break与continue语句的使用场合 2 能够使用break和continue控制程序 两种跳转语句: break与continue语句 含义: break continue break 语句:用于终止块。 ...
NULL 博文链接:https://onestopweb.iteye.com/blog/2359300
主要为大家详细介绍了Java continue break制作简单聊天室程序,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例讲述了Python学习笔记之Break和Continue用法。分享给大家供大家参考,具体如下: Python 中的Break 和 Continue break:控制何时循环应该结束 continue: 跳过循环的一次迭代 Break 和 Continue[示例练习]...
java语言中,break关键字和continue关键字的区别
该文档综合了很多网上关于break和continue的讲解,包含例程,十分详细。该文档综合了很多网上关于break和continue的讲解,包含例程,十分详细。
通过求圆的面积来演示break和continue的作用,是这两个的功能更加明确
您可能感兴趣的文章:Python跳出循环语句continue与break的区别python中的break、continue、exit()、pass全面解析Python循环语句之break与continue的用法python中break、continue 、exit() 、pass终止循环的区别详解...
Python由荷兰数学和计算机科学研究学会的吉多·范罗苏姆于1990年代初设计,Python提供了高效的高级数据结构,还能简单有效地面向对象编程。Python语法和动态类型,以及解释型语言的本质,使它成为多数平台上写脚本和...
js----while循环+do while循环+continue+break
java跳出循环break;return;continue使用 . java跳出循环break;return;continue使用 . java跳出循环break;return;continue使用
php中常用的for与foreach循环中,经常遇到条件判断或中止循环的情况。而处理方式主要用到break及continue两个流程控制指令,现在说明主要区别
Python由荷兰数学和计算机科学研究学会的吉多·范罗苏姆于1990年代初设计,Python提供了高效的高级数据结构,还能简单有效地面向对象编程。Python语法和动态类型,以及解释型语言的本质,使它成为多数平台上写脚本和...
break语句和continue语句在while循环和for循环中都可以使用,并且一般常与选择结构或异常处理结构结合使用。 Python中的break语句用来终止循环语句,即循环条件没有满足要求,也会停止执行循环语句。 continue 语句...
主要介绍了Java中break、continue、return语句的使用区别对比,本文用非常清爽简明的语言总结了这三个关键字的使用技巧,并用一个实例对比使用结果,需要的朋友可以参考下
博客源码:https://blog.csdn.net/u014411348/article/details/108527497
千锋Web前端教程_18_循环_break和continue
英文关键字支持库,为易语言提供 if switch while for continue break return 等英文形式的流程控制语句,其功能和用法与易语言核心库中相关命令完全等同。使用本支持库编写的易语言程序,运行时不需要依赖本支持库...
比较了break与continue的用法不同之处