title: Comparing a number with an array of numbers
body: <p>I want to write a code wherein I have to compare a number with all the elements of an array. The number can be equal to only one element of an array or not equal to any element. I can compare the number with each element of the array using if statement inside a for loop. Problem is when I want to write "the number is not equal to any of the element of the array".The code shown below will execute the else statement 99 or 100 times, but I need that to be executed only once, after number is compared with all X[i] and not found equal.</p>
  
  <pre><code>for(int i = 0; i &lt; 100; i++)
  {
      if(number == X[i])
      {
          cout &lt;&lt; "number is equal to one of the numbers in array" &lt;&lt; endl;
      }
      else
      {
          cout &lt;&lt; "number is not equal to any number in the array" &lt;&lt; endl;
      }
  }
  </code></pre>