break the foreach loop without completion
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/456276/exiting-foreach-loop-in-c-sharp">Exiting Foreach loop in C#</a>  </p>
</blockquote>



<p>I need to compare two registry key i.e HKEY_USER and  HKEY_CURRENT_USER.</p>

<pre><code>I am using two methods..both are having foreach loops..
</code></pre>

<p>The first method calls another method which also having foreach loop. After performing required operation the condition should go to the first loop which is in the first method and also where the condition goes to the next loop..</p>

<p>Simply, breaking the inner loop and maintaining the outer loop.</p>

<p>I want to break the inner loop after executing the specific method..</p>

<pre><code>        string[] mainkeys1 = mckey.GetSubKeyNames();

        foreach (string skey1 in mainkeys1)
         {
          ckey = skey1;

           mckey = l1.OpenSubKey(_ckey);

           int mcnt2 = mckey.SubKeyCount;

           if (mcnt2 &gt; 0)
            {
             Getvaluescur();
             RegistryKey l2 = mckey;

             string[] mainkeys2 = mckey.GetSubKeyNames();

                            foreach (string skey2 in mainkeys2)
                            {
                                ckey = skey2;

                                mckey = l2.OpenSubKey(_ckey);

                                int mcnt3 = _mckey.SubKeyCount;

                                if (mcnt3 &gt; 0)
                                  ....
                                  ....
</code></pre>

<p>The above code is also inside the Foreach loop..
I want to break the loop after executing the required methods..</p>

<p>Can anyone guide me to break the Foreach loop without completion..</p>

<p>Thank you..</p>
