[英]what's wrong in this for loop?
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? 这是怎么了
In java for loop the condition should give be a boolean
value so you should use either 在java for循环中,条件应为
boolean
值,因此您应使用其中一个
for(i=0,k=0; i<5&&k<5; i++,k++)
or 要么
for(i=0,k=0; i<5||k<5; i++,k++)
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++)
您需要将其更改为以下内容,以使循环具有布尔表达式:
for(i=0,k=0; i<5 && k<5; i++,k++)
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]);
Why on Earth do you loop on two indistiguishable int
s i
and k
? 为什么地球上的你在两个indistiguishable循环
int
小号i
和k
? according your code k
is just as synonym of i
and can be easily removed. 根据您的代码
k
就像i
同义词,可以轻松删除。 Do it simply as 简单地做
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"
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.