有人可以让我知道一些资源在线,定义为这种奇怪的实时行为?do-while在底部声明
int i = 0;
do while (++i < 1) { //this compile (?!?)
System.out.print("i is " + i);
}
do while (++i < 1) // this compile also
System.out.print("i is " + i);
do while (i > 1) {}
while (i > 1) {} //this doesn't compile, the comp. wants the semicolon
对不起,我错过了do-while语句的内容?
在此没有提及在所有Oracle官方链接: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html
编辑: 对不起,我解释的嵌套,而作为另一个语句。
这是困惑我原来的语句:
int i = 1;
do while (i < 1)
System.out.print("i is " + i);
while (i > 1);
这编译...,等同于:
do {
while (++i < 1) // this compile also!
System.out.print("i is " + i);
}
while (i > 1);
我怀疑',而(I> 1){}'doesn't如果'i'存在编译... – SomeJavaGuy
其实'while(i> 1){}'是唯一可以编译的循环。 – stevecross
你发布的内容不能编译,你在'while(...)之后丢失了一个分号;'我建议你阅读JLS:https://docs.oracle.com/javase/specs/jls/se8/ html/jls-14.html#jls-14.13 – Tunaki