标签: continue

Java循环效率.如果 - 继续或如果

今天在完成任务时正在考虑的问题是关于循环效率.

让我们说.我有一个数组{'a','x','a','a'}和一个应该避免 'x'元素的循环现在我想知道这两种方法在效率方面是如何不同的 - 不要花时间或做 - 或者用于循环区分

char[] arrExample = {'a','x','a','a'};
for(int idx = 0; idx<arrExample.length; idx++){
    if(arrExample[idx] == 'x')
        continue;

    System.out.println(arrExample[idx]);
}
Run Code Online (Sandbox Code Playgroud)

而公共循环看起来像这样

char[] arrExample = {'a','x','a','a'};
for(int idx = 0; idx<arrExample.length; idx++){
    if(arrExample[idx] != 'x')
        System.out.println(arrExample[idx]);
}
Run Code Online (Sandbox Code Playgroud)

所以...专家评论很高兴.谢谢!

java performance loops if-statement continue

2
推荐指数
1
解决办法
4616
查看次数

在Python for循环中跳过可变数量的迭代

我有一个列表和一个for循环,如下所示:

mylist = ['foo','foo','foo','bar,'bar','hello']
for item in mylist:
    cp = mylist.count(item)
    print("You "+item+" are present in "+str(cp)+" copy(ies)")
Run Code Online (Sandbox Code Playgroud)

输出:

You foo are present in 3 copy(ies)
You foo are present in 3 copy(ies)
You foo are present in 3 copy(ies)
You bar are present in 2 copy(ies)
You bar are present in 2 copy(ies)
You dude are present in 1 copy(ies)
Run Code Online (Sandbox Code Playgroud)

预期产量:

You foo are present in 3 copy(ies)
You bar are present in 2 copy(ies)
You dude are present …
Run Code Online (Sandbox Code Playgroud)

python for-loop continue

2
推荐指数
1
解决办法
198
查看次数

为什么循环没有停止使用'继续'?

所以我是编程新手,我正在编写一些练习代码(Python 3.6):

while True:
    print('Hello Steve, what is the password?')
    password = input()
    if password != '1234':
        continue
    print('Access granted')
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,即使我输入正确的密码,循环仍然继续.你能帮我弄清楚我做错了什么吗?

python continue while-loop python-3.x

2
推荐指数
1
解决办法
185
查看次数

在 do while 循环中的 continue 语句

#include <stdlib.h>
#include <stdio.h> 
enum {false, true}; 
    
int main() 
{ 
   int i = 1; 
   do
   { 
      printf("%d\n", i); 
      i++; 
      if (i < 15) 
        continue; 
   } while (false); 
      
   getchar(); 
   return 0; 
} 
Run Code Online (Sandbox Code Playgroud)

continue在这段代码中执行语句后会发生什么?

控制去哪儿了?

c continue while-loop

2
推荐指数
3
解决办法
716
查看次数

Lua goto 语句模拟继续引发的错误

通常,我的目标是模拟 Lua 中不存在的 continue 语句。我已经阅读了一些关于使用 goto 执行此操作的线程。我试过:

for i=0, 9, 1 do
    if i<5 then goto skip end
    print(i)
    ::skip::
end
Run Code Online (Sandbox Code Playgroud)

它提出了“lua:test.lua:2:'='预期在'跳过'附近”

有什么解决方法吗?提前致谢

lua continue

2
推荐指数
1
解决办法
231
查看次数

循环最佳实践

我有一个非常大的循环,循环1000行.如果找到魔术值1,我退出循环.如果未找到魔法值1但发现魔法值2,则循环需要跳到开头.现在我正在使用一个开关,一些ifs和一个goto.我读过goto不是最好的方法.有没有更好的方法来使这项工作?

c# continue break

1
推荐指数
2
解决办法
3191
查看次数

使Magento"继续购物"按钮重定向到最后添加到购物车产品的类别

继续购物按钮在购物车页面上无法正常工作.

单击按钮后,转到主页.

我想去上一个类别页面.

continue magento

1
推荐指数
1
解决办法
8607
查看次数

在Java函数中继续语句

我想创建逻辑,使得:if s2为null,调试器会跳过所有复杂的字符串操作并返回null,而不是s1 + s2 + s3在第一个if块中看到.我错了吗?

public static String helloWorld(String s1, String s2, String s3){
   if(s2==null){
     continue;
     return null;
   }

   ... lots of string manipulation involving s1, s2 and s3.

   return (s1+s2+s3);
}
Run Code Online (Sandbox Code Playgroud)

java iteration algorithm continue

1
推荐指数
1
解决办法
888
查看次数

在Java中使用方法突破循环

我试图在用户退出程序中的while循环之前使用方法进行双重检查.

private static Scanner input = new Scanner(System.in);

public static void ays() {
    System.out.println("Are you sure?");
    String ays = input.nextLine();
    if (ays.equals("Yes")) {
       break; 
    } else {
       continue;
    }
}
Run Code Online (Sandbox Code Playgroud)

运行程序后,我收到错误break outside switch or loop,然后continue outside switch or loop.有没有办法在这里实现我的目标?

java methods loops continue break

1
推荐指数
1
解决办法
3680
查看次数

请解释继续声明

请任何人都可以解释继续声明,我一直在努力将其分解为我的理解,但所有的努力都是徒劳的.这是我在python文档中找到的示例程序,我无法理解它.

for num in range(2, 10):
    if num % 2 == 0:
        print("Found an even number", num)
        continue
    else:
        print("Found a number", num)
Run Code Online (Sandbox Code Playgroud)

python continue python-3.x

1
推荐指数
1
解决办法
143
查看次数