循环里continue,是否后面语句不执行

lilinew 2009-09-14 04:27:03
这里询问 
当 scores[i]=0 或者 attList.get(i)==null的时候
下面的语句 for(int j=0;j<distinctList.size();j++){
if(attList.get(i).equals(distinctList.get(j)))
scores[i]=hash;
}

就不运行了吗?


代码如下
for(int i=0;i<attList.size();i++){
if(scores[i]!=0 || attList.get(i)==null)
continue;
for(int j=0;j<distinctList.size();j++){
if(attList.get(i).equals(distinctList.get(j)))
scores[i]=hash;
}
...全文
1482 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
cwjieNo1 2009-09-14
  • 打赏
  • 举报
回复
后面的不执行了,重新再次开始循环。。。
以下这个例子可以让你更好的理解:

public class TestOne {

public static void main(String[] args) {
int[] a = {2};
for(int i=0; i<5; i++){
if(i==0)
continue;
for(int j = 0 ; j < a.length;j++){
System.out.println(a[j]);
}
}
}
}
TonnyGold 2009-09-14
  • 打赏
  • 举报
回复 1
continue是跳出本次循环,执行下次循环
see_gl 2009-09-14
  • 打赏
  • 举报
回复
if(scores[i]!=0 || attList.get(i)==null)
continue;


你的if 只管下面一行语句 下面得代码还是会执行的
liangwansheng 2009-09-14
  • 打赏
  • 举报
回复
本次不执行,执行后面的。
lilinew 2009-09-14
  • 打赏
  • 举报
回复
int[] scores= { 1, 2, 3, 4, 5 };

测试可以知道如果scores[i]=0 或者 attList.get(i)!=null
才可以往下走, 否则直接跳到循环下一跳。  后面不执行
loveofmylife 2009-09-14
  • 打赏
  • 举报
回复
continue用来打断当前循环过程,从当前循环的最后重新开始执行
你这样写当if(scores[i]!=0 || attList.get(i)==null)成立的时候会跳过后面的语句,继续循环,直到i>=attList.size();
bigbro001 2009-09-14
  • 打赏
  • 举报
回复
continue前面的if条件如果成立,后面的语句就不执行了,如果不成立,就执行,这次不执行,下次可能执行,这次执行,下次可能不执行
imasmallbird 2009-09-14
  • 打赏
  • 举报
回复
continue就是中止本次循环开始下一次循环

if(scores[i]!=0 || attList.get(i)==null)
continue;
这是判断scores[i]!=0或者 attList.get(i)==null的时候就不运行那段代码了~~

这种问题,最好自己跑一下,就知道了,这样还能对continue认识的更加深刻
要是有人回答你说能运行,你是信呢?还是自己实验呢?
gesanri 2009-09-14
  • 打赏
  • 举报
回复
continue是跳出本次循环,继续执行下次循环
justinavril 2009-09-14
  • 打赏
  • 举报
回复
你可以不用考虑这中情况下的continue,写个测试代码自己验证嘛:


for(int i=0; i<5; i++){
if(i==0)
continue;
System.out.println(i);
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧