title: C++ how to check if elements in an array are equal?
body: <p>I am trying to write a program which checks if all the values in an array are equal using a for loop but I cannot figure out a way for the if statement to check if each value in the array are equal other than constantly repeating <code>"if a[i] == a[1] &amp;&amp; a[i] == a[0]"</code> and so on. I do not want to do that as i want it to work for any array of any size.  Any help is much appreciated!</p>
  
  <pre><code>    for (unsigned i = 0; i &lt; val; i++){
         if (a[i] == a[0])
            return true;
         else
            return false;
      }
  </code></pre>