Yes, it's optional.
There are a couple of things that you can do here:
The second thing you can do is, instead of using an if statement inside of a for loop, you can use a while loop. Something along the lines of:
int i = 0;
while( number != X[i] )
what this does is loop until number is equal to an element in the array, and if is not equal to an element in the array you increment to the next element of the array.
I may have misinterpreted your question, so lmk if that helped