### For Loop if statment

What I am trying to get done is use the if statement in the for loop to test both of the arrays and see if they are equal to zero. I tried doing an if statement with a logical or that looked like this
` if (myArray[i] == 0 || myArray2[i] == 0)`

and it did not work.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` `````` #include using namespace std; int const arraySize = 10; int myArray[arraySize] = {0,0,0,0,1,0,0,0,0,0}; int myArray2[arraySize] = {1,2,3,4,5,6,0,8,9,0}; class test { public: void testZero( int i) //Test if the array equals zero. { for (int i = arraySize - 1; i >=0; i--) { if (myArray[i] == 0) { cout << "True" << endl; } else { cout << "False" << endl; } } } }; int main() { test myTest; int forLoop; myTest.testZero(forLoop); return 0; } ``````
Why does testZero take an int...? Furthermore, you probably want it to return a bool to indicate whether the array is zero or not.

When you say if an array is "equal to zero", do you mean one element is equal to zero or all elements are equal to zero?

Case one element: Return true on line 19 and false just below line 26. On line 19, it'll have found its one zero element and does not need to continue.

Case all elements: Return false on line 23 and true just below line 26. On line 19, it'll have found one nonzero element, which means that not all the elements are zero.

Just a suggestion. :)

-Albatross
Topic archived. No new replies allowed.