Cannot execute code after the loop in c++ : <p>I'm facing a problem in c++ that I don't understand.</p>

<p>this is my code:</p>

<pre><code>auto DataArray = jvalue.at(U("data")).as_array();
std::cout &lt;&lt; "Outside the loop, first output" &lt;&lt; std::endl;

for (int i = 0; i &lt;= 10; i++)
{
    auto data = DataArray[i];
    auto dataObj = data.as_object();

    std::wcout &lt;&lt; "inside the loop" &lt;&lt; std::endl;
}

std::cout &lt;&lt; "Outside the loop, second output" &lt;&lt; std::endl;
</code></pre>

<p>Output:</p>

<pre><code>Outside the loop, first output
inside the loop
inside the loop
inside the loop
inside the loop
inside the loop
inside the loop
inside the loop
inside the loop
inside the loop
inside the loop
Press any key to continue . . .
</code></pre>

<p>It seems the code stops after the loop reach its end.
But why?</p>

<p>But if I commented out the </p>

<pre><code>//auto data = DataArray[i];
//auto dataObj = data.as_object();
</code></pre>

<p>it doesn't have a problem.</p>

<p>By the way I'm working on cpprest and get json object data from api.
The <code>jvalue</code> variable holds the result.</p>

<p>And if I try and catch the code:</p>

<pre><code>try {
    auto data = DataArray[i];
    auto dataObj = data.as_object();
    std::wcout &lt;&lt; "inside the loop" &lt;&lt; std::endl;
}
catch (const std::exception&amp; e) {
    std::wcout &lt;&lt; e.what() &lt;&lt; std::endl;
}
</code></pre>

<p>the result is infinite loop with output: <code>not an object</code>.</p>

<p>Please help. Thank you.</p>
