[code="java"]
class Example {
public static void main(String[] args) {
http://www.iteye.com
System.out.println("Hello World!");
}
}
[/code]
[b]上面为在[url]http://www.iteye.com/topic/412868[/url]看到的,其中的一小段代码,没看懂为什么可以像
“http:”
这种写法。
[/b]
[b]问题补充:[/b]
[b]2楼兄弟的代码没通过运行...[/b]
朋友,
很简单嘛
[code="java"]
import java.io.IOException;
public class LabelTest {
public static void main(String[] args) throws IOException {
char a;
outer: // this is the label for the outer loop
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
a = (char) System.in.read();
if (a == 'b')
break outer;
if (a == 'c')
continue outer;
}
}
}
}
[/code]
http就是定义一个label嘛,
//www.iteye.com
这个就是一般的注释啊,有什么不好理解呢
标号label
标号提供了一种简单的break语句所不能实现的控制循环的方法,当在循环语句中碰到break时,不管其它控制变量,都会终止。但是,当你嵌套在几层循环中想退出循环时又会怎样呢?正常的break只退出一重循环,你可以用标号标出你想退出哪一个语句。
char a;
outer: //this is the label for the outer loop
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
a=(char)System.in.read();
if(a==´b´)
break outer;
if(a==´c´)
continue outer;
}
}
在这个例子中,循环从键盘接受100个输入字符,输入“b”字符时,break outer语句会结束两重循环,注重continue outer语句,它告诉计算机退出现在的循环并继续执行outer循环。
楼上的正解,标号是也.
同意。http:是标签的定义,后面的//是注释
在Java中可以使用 break/continue 语句来控制多重嵌套循环的跳转。
public static void main(String[] args) {
http: //www.iteye.com
for(int i = 0; i < 10; i++){
System.out.println("i = " + i);
for (int x = 0; x < 10; x++){
System.out.println("x = " + x);
continue http;
}
}
}