- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Java 的新手,正在为 OCA 做准备。我正在尝试使用 break 和 continue 标签。根据指南中的描述,似乎既有标签,也只是将控件带到标签上。但是使用测试代码既不会在 break 标签为较早行时抛出错误,也不会从标签开始执行。
虽然我永远不会使用 break 和 continue 标签。但从考试的角度理解它很重要。
示例代码:
public class B{
public static void main(String[] args){
int i = 0;
label1: for(;i<=10;i++){
System.out.println(i);
if(i==4)
continue label1;
}
System.out.println("out" + i);
i=0;
label2: for(;i<=10;i++){
System.out.println(i);
if(i==4)
break label2;
}
System.out.println("out" + i);
}
}
结果:
java B
0
1
2
3
4
5
6
7
8
9
10
out11
0
1
2
3
4
out4
为什么 break 不从 label 继续执行?
还包括指南书中的摘录:
我从 Yassir 的回答中的例子中理解:
标签后面应该有一个 block 。
continue 在 block 的开头带来控制,break 在结尾带来控制。谢谢
最佳答案
这两种说法是有区别的。
A break statement transfers control out of an enclosing statement.
[...] Control passes to the loop-continuation point of an iteration statement.
下面是两个非常简单的例子,在现实生活中一点用处都没有,只是为了演示使用不同语句的 Action 。
// This will print "continue" forever.
CONTINUE_LOOP:
while(true) {
System.out.println("continue");
continue CONTINUE_LOOP;
}
// This will only print "break" once and then break out of the loop
BREAK_LOOP:
while(true) {
System.out.println("break");
break BREAK_LOOP;
}
关于java - 打破标签不给标签带来控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36359317/
当我为我的项目运行“mvn dependency:tree”时,它显示如下: [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ x
我调用 ajax 的脚本 function search_func(value) { $.ajax({ type: "GET", url: "sample.php
我正在使用 SIM 安装 Sitecore 8.1,但在打开启动板时,由于 ajax 请求返回 HTTP 500 错误,出现了几个 Javascript 错误。查看开发人员工具会显示以下消息: htt
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我有一张 table : +-----------+-------------+------+-----+---------+-------+| Field | Type | N
所以,我对这个阵列很生气,第 2 天让我感到疼痛 *.... 我正在开发面向对象的 PHP 脚本。 我得到一个数组: Array ( [0] => Project Object ( [project_
我正在尝试将我的一个 Rails 项目升级到 Ruby 1.9.2。一切进展顺利,但一个 RSpec 测试失败了。在这个测试中,我需要一个Ruby lib: # file spec/models/my
我可以使用 Maven 的插件 spring-boot:run 运行 Spring Boot,但是当我尝试执行打包的 jar 时,它给出: Error creating bean with name
我是一名优秀的程序员,十分优秀!