Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Breaking out of an Iterative Statement in C#

This example uses the break statement to break out of a for loop when an integer counter reaches 10.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ForgetCode
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. for (int counter = 1; counter <= 1000; counter++)
  13. {
  14. if (counter == 10)
  15. break;
  16. Console.WriteLine(counter);
  17. }
  18. }
  19. }
  20. }


Output:
1 to 9 will be printed. Rest of the numbers will be ignored since break was rendered.