How to

break out of loop

Published: 9. October 2011 | Updated: 9. October 2011
License: Microsoft Public License (MS-PL)
Categories: Collections
Tags: C# Collections
Was this snippet helpful for you? YESYES / NONO
var data = new[] { 1, 2, 3, 4, 5 };
            
// works also for 'while' and 'for' 
foreach (int i in data)
{
    if (i == 3) break; // breaks out of loop
}
Send us feedback about this snippet »



Related Snippets: