Note that there are some explanatory texts on larger screens.

plurals
  1. POBreaking out of if statement
    primarykey
    data
    text
    <p>I am writing a program in which I use an if statement to check some condition; if true I increment a counter. The problem is that as soon as the statement is true the variable either gets incremented endlessly or by random number.</p> <p>I have been trying to use some clause to break out of this statement if condition meet but with no luck </p> <p>my code: </p> <pre><code>if(res_vect_angle &gt;=60 &amp;&amp; res_vect_angle &lt;=100 &amp;&amp; left_mag_b &gt;100) { //line(drawing, *iter_s, *(iter_s -1), Scalar( 255, 255, 255 ), 2,8 ); left_hook_count++; cout&lt;&lt;"Left Hook:..........................!!! "&lt;&lt;left_hook_count&lt;&lt;endl; if(left_hook_count++ == true) { break; } } </code></pre> <p>The whole chunk of code associated with the issue:</p> <pre><code>float M1, M2; float A1, A2; double left_mag_a, left_mag_b; double res_vect_angle; int i = 0; for(vector&lt;Point&gt;::iterator iter_lh = Leftarm.begin(); iter_lh != Leftarm.end(); ++iter_lh) { if(iter_lh-&gt;y &lt;=240 &amp;&amp; iter_lh-&gt;y &gt;=60 &amp;&amp; iter_lh-&gt;x &gt;=340 &amp;&amp; iter_lh-&gt;x &lt;=680) { left_detect.push_back(*iter_lh); if(i % 4 == 0) { if(left_detect.size()&gt;4) { for(vector&lt;Point&gt;::iterator iter_s = left_detect.begin()+3; iter_s != left_detect.end(); ++iter_s, i++) { //Resultant Magnetude M1 = pow((double) iter_s-&gt;x + (iter_s -2)-&gt;x,2); M2 = pow((double) iter_s-&gt;y + (iter_s -2)-&gt;y,2); left_mag_a = (M1 + M2); left_mag_b = sqrt(left_mag_a); //Resultant Angle A1 = abs(iter_s-&gt;x - (iter_s -2)-&gt;x); A2 = abs(iter_s-&gt;y - (iter_s -2)-&gt;y); res_vect_angle = abs(atan2(A1,A2) * 180 /PI); //cout&lt;&lt;"LEFT HOOK ANGLE IS: "&lt;&lt;res_vect_angle&lt;&lt;endl; if(res_vect_angle &gt;=60 &amp;&amp; res_vect_angle &lt;=100 &amp;&amp; left_mag_b &gt;100) { //line(drawing, *iter_s, *(iter_s -1), Scalar( 255, 255, 255 ), 2,8 ); left_hook_count++; cout&lt;&lt;"Left Hook:..........................!!! "&lt;&lt;left_hook_count&lt;&lt;endl; if(left_hook_count++ == true) { break; } } } } } } } </code></pre> <p>Hope this helps guys ps. <code>left_hook_count++;</code> is a int variable declared on top of my main().</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload