我目前(过去也曾)使用此循环来查看自定义类数组,并确保数组中每个类的布尔成员值相等。有没有更好的(更有效,可能更简单的编码)方法来做到这一点?
由于这种解释非常糟糕,并且缺乏更好的解释方法,我会简单地问:“有没有更好的方法来优化‘这个’循环?”
//set to true so the loop runs
boolean AllArentEqual = true;
while (AllArentEqual){
//do some stuff to make stuff equal
///// Check if stuff is equal /////
//set to false to determine later
AllArentEqual = false;
//check if any aren't equal
for (int i = 1; i < anArrayOfClass.length; i++){
if (anArrayOfClass[i - 1].BooleanValue != anArrayOfClass[i].BooleanValue){
//one isn't equal so set the loop to be re-run
AllArentEqual = true;
}
}
} //loop until stuff is equal