这个for循环有什么问题?

时间:2022-10-29 00:09:04
int i, k, j;
    for(j=0; j<5; j++)
    for(i=0,k=0; i<5,k<5; i++,k++)
        System.out.print(c[i]+" : "+p[i][j][k]);

I got compiler error for this statement

我有这个声明的编译器错误

for(i=0,k=0; i<5,k<5; i++,k++)

what is wrong here?

这有什么不对?

6 个解决方案

#1


2  

In java for loop the condition should give be a boolean value so you should use either

在java for循环中,条件应该是一个布尔值,所以你应该使用

for(i=0,k=0; i<5&&k<5; i++,k++)

or

for(i=0,k=0; i<5||k<5; i++,k++)

#2


1  

Use

for(i=0,k=0; i<5&&k<5; i++,k++)

OR

for(i=0,k=0; i<5||k<5; i++,k++)

instead of

for(i=0,k=0; i<5,k<5; i++,k++)

#3


0  

You need to change it to the following to have a boolean expression for the loop:

您需要将其更改为以下内容以获得循环的布尔表达式:

for(i=0,k=0; i<5 && k<5; i++,k++)

#4


0  

If you want to check the both condition then just try the || or && so that it can run....

如果你想检查这两个条件,那么只需尝试||或&&以便它可以运行....

for(i=0,k=0; i<5||k<5; i++,k++)
for(i=0,k=0; i<5&&k<5; i++,k++)

int i, k, j;
for(j=0; j<5; j++)
    for(i=0,k=0; i<5||k<5; i++,k++)
        System.out.print(c[i]+" : "+p[i][j][k]);

#5


0  

Why on Earth do you loop on two indistiguishable ints i and k? according your code k is just as synonym of i and can be easily removed. Do it simply as

你为什么在地球上循环使用两个不可分割的整数i和k?根据你的代码k就像我的同义词,可以很容易地删除。简单地说就是这样

  for (int j = 0; j < 5; j++)
    for (int i = 0; i < 5; i++)
      System.out.print(c[i] + " : " + p[i][j][i]); // "k" is "i"

#6


0  

As said before, the condition must be a single one.

如前所述,条件必须是单一条件。

If you want it to run while at least one of the two is under the given value use:

如果您希望它在两个中的至少一个低于给定值的情况下运行,请使用:

i<5 || k<5

If you want it to run untill one of the two surpasses the given value use:

如果你想要它运行,直到两个超过给定值之一使用:

i<5 && k<5

#1


2  

In java for loop the condition should give be a boolean value so you should use either

在java for循环中,条件应该是一个布尔值,所以你应该使用

for(i=0,k=0; i<5&&k<5; i++,k++)

or

for(i=0,k=0; i<5||k<5; i++,k++)

#2


1  

Use

for(i=0,k=0; i<5&&k<5; i++,k++)

OR

for(i=0,k=0; i<5||k<5; i++,k++)

instead of

for(i=0,k=0; i<5,k<5; i++,k++)

#3


0  

You need to change it to the following to have a boolean expression for the loop:

您需要将其更改为以下内容以获得循环的布尔表达式:

for(i=0,k=0; i<5 && k<5; i++,k++)

#4


0  

If you want to check the both condition then just try the || or && so that it can run....

如果你想检查这两个条件,那么只需尝试||或&&以便它可以运行....

for(i=0,k=0; i<5||k<5; i++,k++)
for(i=0,k=0; i<5&&k<5; i++,k++)

int i, k, j;
for(j=0; j<5; j++)
    for(i=0,k=0; i<5||k<5; i++,k++)
        System.out.print(c[i]+" : "+p[i][j][k]);

#5


0  

Why on Earth do you loop on two indistiguishable ints i and k? according your code k is just as synonym of i and can be easily removed. Do it simply as

你为什么在地球上循环使用两个不可分割的整数i和k?根据你的代码k就像我的同义词,可以很容易地删除。简单地说就是这样

  for (int j = 0; j < 5; j++)
    for (int i = 0; i < 5; i++)
      System.out.print(c[i] + " : " + p[i][j][i]); // "k" is "i"

#6


0  

As said before, the condition must be a single one.

如前所述,条件必须是单一条件。

If you want it to run while at least one of the two is under the given value use:

如果您希望它在两个中的至少一个低于给定值的情况下运行,请使用:

i<5 || k<5

If you want it to run untill one of the two surpasses the given value use:

如果你想要它运行,直到两个超过给定值之一使用:

i<5 && k<5