[英]How to stop for loop once it has been looped to all records in a list
I am using for loop in my program, and i want to know how can i stop this once it has been looped to all records in a list one by one. 我在程序中使用for循环,并且我想知道一旦将它逐一循环到列表中的所有记录,该如何停止。
btnSyncAll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
for (int i=0; i<ImageList.size(); i++)
{
new SyncFileAsync().execute(String.valueOf(i));
}
}
});
The idea of a for loop is that it stops after it looped from int i = 0
to i < imageList.size()
. for循环的想法是,它在从int i = 0
循环到i < imageList.size()
之后停止。 I dont know why you have the feeling that it doesnt, but probably your imageList
is really big and it takes a lot of time until the loop is finished. 我不知道为什么会有这种感觉,但是您的imageList
可能确实很大,并且要花很多时间才能完成循环。
For loop stops iterating when it reaches the limit you defined in for loop statement. 当达到您在for循环语句中定义的限制时,for循环将停止迭代。 But if you want to stop in middle you have to put break with certain condition check. 但是,如果您想在中间停下来,则必须对某些条件进行检查。
ie 即
for(int i=0;i < n;i++){ for(int i = 0; i <n; i ++){
if(i==4){
break;
}
} }
if you want to not to execute for particular iteration use continue statement. 如果您不想执行特定的迭代,请使用continue语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.