简体   繁体   English

一旦循环到列表中的所有记录,如何停止循环

[英]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.

相关问题 一旦在 Java 中执行了程序,如何让 for 循环停止运行并继续执行下一个方法? - How can I get the for loop to stop to stop running and proceed to the next methid once the program has been executed in Java? 如何确保在循环遍历列表后添加的Java并发列表中的元素得到正确处理? - How to make sure elements of a concurrent list in java, that are added after the list has been looped through, are handled properly? 如何立即停止循环运行 - How to stop for loop running all at once 变量设置为false后,如何停止线程? - How to stop threads once variable has been set to false? 一旦线程被中断,如何完全停止线程? - How to completely stop a thread once it has been interrupted? 绘制图形后如何创建邻接表? - How to create adjacency list once a graph has been plotted? 一旦达到特定的障碍,如何停止动画? - How do I stop an animation once a certain barrier has been reached? 您可以在while循环中停止检查一次是否通过一次吗? - Can you stop checking a if once it has passed once, in a while loop? 一旦用户输入了正确的答案,如何停止重复这个循环? - How do I stop this loop from repeating once the user has entered the correct answer? 满足条件后有没有办法停止扫描仪输入循环? - Is there a way to stop scanner input loop after the condition has been met?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM