// for exemple . boolean inCycle = true; for(i=0;i<100 && inCycle;i++){ for(j=0;j<100 && inCycle;j++){ for(k=0;k<100 && inCycle;k++){ //... Other codes ... if(condition must be break){ inCycle=false;break; } } } }
public class test{ public void test(){ int i=4; ok:for(int j=0;j<10;j++) //这是java里面的特定的标号 //作用是跟goto语句差不多 for(int k=0;k<10;k++){ if(k==i){ break ok; //这里就是break到ok这里 } }
boolean inCycle = true;
for(i=0;i<100 && inCycle;i++){
for(j=0;j<100 && inCycle;j++){
for(k=0;k<100 && inCycle;k++){
//... Other codes ...
if(condition must be break){
inCycle=false;break;
}
}
}
}
public class test{
public void test(){
int i=4;
ok:for(int j=0;j<10;j++)
//这是java里面的特定的标号
//作用是跟goto语句差不多
for(int k=0;k<10;k++){
if(k==i){
break ok;
//这里就是break到ok这里
}
}
}
}你可以百度搜下 我记得好像就是这样用的
public class LabelInLoop{
public static void main(String[] args){
outer:
//此处不能有其他语句,因为循环体中使用了outer
for(int i=0;i<=3;i++)
{
for(int j=0;j<=3;j++)
{
for(int k=0;k<=3;k++)
{
if(k==1 && j==1 && i==1){
System.out.println("break outer");
break outer;
}
}
}
}
}
}
public class LabelInLoop{
public static void main(String[] args){
outer:
//此处不能有其他语句,因为循环体中使用了outer
for(int i=0;i<=3;i++)
{
for(int j=0;j<=3;j++)
{
for(int k=0;k<=3;k++)
{
if(k==1 && j==1 && i==1){
System.out.println("break outer");
break outer;
}
}
}
}
System.out.println("hello");
}
}你运行看看这段代码,
看是不是输出
break outer
hello
public static void main(String[] args) {
out: for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if(j == 0){
break out;
}
}
System.out.println("out");
}
System.out.println("aaa");
}
for(int i=0;(i<length)&&!flag;i++){
for(方法同上){
for(方法同上)
{
if(找到)
flag = true;
}
}
}楼主试试
for(int i=0;(i<length)&&!flag;i++){
for(方法同上){
for(方法同上)
{
if(找到)
flag = true;
}
}
}楼主试试
那LZ应该 审核下自己代码了
。
。
。
。
break loop;