我的布尔表达式在循环中间变为假。我应该使用什么样的循环?我一直在阅读循环教程,每个教程都提到 while 循环不能做到这一点。我尝试将 for 循环和 if 语句结合起来,但这也不起作用。对不起这个简单的问题。
}
for(int k = 0;k < collb.length; k++){
//what was used after first calculation
grosssum += col4[k]*mix[k];
one=sum1 - grosssum;
}
for(int n = 0;n < collb.length; n++)
if(one < -need[n] && col4[n] >0){
col5[n]=col4[n]-inc[n] + arrayspecificpounds[n];
net += col5[n]*mix[n];
sum = sum1-net;
} //net is the sum of what was used * mix
//sum1 is what we started with
else{
if(one > need[n] && col4[n] >0){
col5[n]=col4[n]-inc[n] + arrayspecificpounds[n];
net += col5[n]*mix[n];
sum = sum1-net;
}
else col5[n] = col4[n] + arrayspecificpounds[n];
sum = sum1 - net;
}
for(int p = 0;p< collb.length; p++){
if(sum < -need[p] && col5[p] >0){
col6[p]=col5[p]-inc[p] + arrayspecificpounds[p];
net2 += col6[p]*mix[p];
sum2 = sum1 - net2;
}
else{
if(sum > need[p] && col5[p] >0){
col6[p]=col5[p]+inc[p] + arrayspecificpounds[p];
net2 += col6[p]*mix[p];
sum2 = sum1 - net2;
}
else col6[p] = col5[p] + arrayspecificpounds[p];
net2 += col6[p]*mix[p];
sum2 = sum1 - net2;
}
}
for(int q =0;q< collb.length; q++){
if(sum2 < -need[q] && col6[q] >0){
colr[q]=col6[q] - inc[q] +arrayspecificpounds[q];
}
else{
if(sum2 > need[q] && col6[q]>0){
colr[q]=col6[q] +inc[q] + arrayspecificpounds[q];
}
else colr[q] = col6[q] + arrayspecificpounds[q];
}
在这个例子中 sum2 的值随着数组 col6 的增加而改变,但在数组的中间不等式会改变。一旦 sum2 更改,我将如何实现中断以停止?