here is my code:

``````//if any of errprLists is not equal to 0, then initialWieght equals newWeight
if(errorList[0]!=0 || errorList[1]!=0 || errorList[2]!=0 || errorList[3]!=0)
{
for(int i=0; i<row; i++)
{

initialWeight[i] = newWeight[i];

}
}

//break the loop if all errors equal 0
//---------------------------------------------------------------------------
else if(errorList[0]==0 && errorList[1]==0 && errorList[2]==0 && errorList[3]==0)
break;``````

what i want to do is to shorten those errorLists, but i dont know how to do it
when i write

``````for(int j=0; j<errorList.length; j++){
if(errorList[j]!=0) ....
}``````

it doesnt work
thanks
:(

## All 4 Replies

You basically try to find if any of error list are equal or not equal to 0
Then put some sumerr integer and get sum of all errorLists...

``````int errsum=0;
for (int j=0;j<errorList.length;j++)
errsum+=errorList[J]; // i'll make sum of all  errorList.If some of ErrLists are != 0 then sum is != 0

//Now check if sum is or not is equal to 0

if (errsum ==0)
{
break; //you want to break if all are equal to 0you code if equal
}
else
{
for(int i=0; i<row; i++)
{
initialWeight[i] = newWeight[i];
}
}``````
``````boolean all() {
//&&
int counter = 0;
for (int j = 0; j < errorList.length; j++) {
if (errorList[j] == 0) {
counter++;
}
}
return counter == errorList.length;
}

boolean oneOf() {
//||
for (int j = 0; j < errorList.length; j++) {
if (errorList[j] != 0) {
return true;
}
}
return false;
}
...

if (oneOf()) {
System.arraycopy(newWeight, 0, initialWeight, 0, row);
}

...``````

useful: http://en.wikipedia.org/wiki/De_Morgan's_laws

You basically try to find if any of error list are equal or not equal to 0
Then put some sumerr integer and get sum of all errorLists...

``````int errsum=0;
for (int j=0;j<errorList.length;j++)
errsum+=errorList[J]; // i'll make sum of all  errorList.If some of ErrLists are != 0 then sum is != 0

//Now check if sum is or not is equal to 0

if (errsum ==0)
{
break; //you want to break if all are equal to 0you code if equal
}
else
{
for(int i=0; i<row; i++)
{
initialWeight[i] = newWeight[i];
}
}``````

Thank you so much :)

``````boolean all() {
//&&
int counter = 0;
for (int j = 0; j < errorList.length; j++) {
if (errorList[j] == 0) {
counter++;
}
}
return counter == errorList.length;
}

boolean oneOf() {
//||
for (int j = 0; j < errorList.length; j++) {
if (errorList[j] != 0) {
return true;
}
}
return false;
}
...

if (oneOf()) {
System.arraycopy(newWeight, 0, initialWeight, 0, row);
}

...``````

useful: http://en.wikipedia.org/wiki/De_Morgan's_laws

Thank you so much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.