Break and Continue statements in C#
Dec 23, 2020 05:17 0 Comments C# (C-Sharp) PARTH

        Break and Continue statements in C#  

Break Statement In C#, the break statement is used to terminate the execution from the current loop. A break statement is almost always associated with an if statement.   Let’s see an example –

using System;

class Program

{  

static void Main(string[] args)  

{   

  for(int i=1; i <= 10 ; i++)

    {    

     Console.WriteLine($”i={i}”);

        if(i == 5)       

      break;   

  }  

}

}

Output – i=1 i=2 i=3 i=4 i=5   Continue Statement The continue statement is used when you want to skip the remaining part of the loop, return to the top of the loop and continue a new iteration. The continue statement is commonly associated with an if statement.   Let’s

see an example –

using System;

class Program

{

  static void Main(string[] args)

  {    

for(int i=1; i <= 10 ; i++)   

  {    

     if(i == 5)  

           continue;  

       Console.WriteLine($”i={i}”);

    }

  }

}

Output – i=1 i=2 i=3 i=4 i=6 i=7 i=8 i=9 i=10          

Prev Next
About the Author
Topic Replies (0)
Leave a Reply
Guest User

You might also like

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect