Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You want:</p> <pre><code>foreach (int number in numbers) // &lt;--- go back to here --------+ { // | if (number &lt; 0) // | { // | continue; // Skip the remainder of this iteration. -----+ } // do work } </code></pre> <p>Here's more about the <a href="http://msdn.microsoft.com/en-us/library/923ahwt1.aspx" rel="noreferrer"><strong><code>continue</code> keyword</strong></a>.</p> <hr/> <p><strong>Update:</strong> In response to Brian's follow-up question in the comments:</p> <blockquote> <p>Could you further clarify what I would do if I had nested for loops, and wanted to skip the iteration of one of the extended ones?</p> <pre><code>for (int[] numbers in numberarrays) { for (int number in numbers) { // What to do if I want to // jump the (numbers/numberarrays)? } } </code></pre> </blockquote> <p>A <code>continue</code> always applies to the nearest enclosing scope, so you couldn't use it to break out of the outermost loop. If a condition like that arises, you'd need to do something more complicated depending on exactly what you want, like <code>break</code> from the inner loop, then <code>continue</code> on the outer loop. See here for the documentation on the <a href="http://msdn.microsoft.com/en-us/library/adbctzc4.aspx" rel="noreferrer"><strong><code>break</code> keyword</strong></a>. The <code>break</code> C# keyword is similar to the Perl <code>last</code> keyword.</p> <p>Also, consider taking Dustin's suggestion to just filter out values you don't want to process beforehand:</p> <pre><code>foreach (var basket in baskets.Where(b =&gt; b.IsOpen())) { foreach (var fruit in basket.Where(f =&gt; f.IsTasty())) { cuteAnimal.Eat(fruit); // Om nom nom. You don't need to break/continue // since all the fruits that reach this point are // in available baskets and tasty. } } </code></pre>
 

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