Having trouble looping through an array in c++ : <p>I seem to be looping through my array wrong, I've got it set up to prompt the user for a list of numbers and I am supposed to be comparing it to another number that the user sets. </p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
bool chk = true;
int main() {
    /*
    Write a program that asks the user to type 10 integers of an array and an integer s.
    Then search the value s from the array and display the value of s if it is found in
    the array otherwise print sorry not found..
    */

    int userArray[10], i, greater = 0;
    int s;
    cout &lt;&lt; "Enter a check number: \n";
    cin &gt;&gt; s;
    if (chk = true) {
    //prompt for array list
        for (i = 0; i &lt; 9; i++) {

            if (i == 0) {
                cout &lt;&lt; "Enter ten numbers: " &lt;&lt; "\n";
                cin &gt;&gt; userArray[i];
            }
            else {
                cin &gt;&gt; userArray[i];
            }
            chk = false;
        }
        //loop through the array
        for (int i = 0; i &lt;= 10; i++) {
            if (s = userArray[i]) {
                //for testing
                cout &lt;&lt; userArray[i];
                //cout &lt;&lt; s;
            }
            else {
                cout &lt;&lt; "No match found!";
            }
            //I was just using this to pause the console and let me inspect result
            cin &gt;&gt; greater;

        return 0;

        }
    }
}
</code></pre>

<p>I assume the following code is where the problem lies. The idea is i set s = 2 enter in a list of numbers and then compare to s and print s if there is a match if not I print No match found. When I enter in a number that i know matches s it seems to print the first number in the array, but i thought since I loop through the numbers one by one in the for loop that it should display when it reaches the right number not when it stops. Thanks in advance</p>

<pre><code>    //loop through the array
    for (int i = 0; i &lt;= 10; i++) {
        if (s = userArray[i]) {
            //for testing
            cout &lt;&lt; userArray[i];
            //cout &lt;&lt; s;
        }
        else {
            cout &lt;&lt; "No match found!";
        }
</code></pre>
