YouTip LogoYouTip

Csharp Break Statement

# C# break Statement [![Image 4: C# Loops](#) C# Loops](#) The **break** statement in C# has two main uses: 1. When the **break** statement is encountered inside a loop, the loop is immediately terminated, and program control resumes at the next statement following the loop. 2. It can be used to terminate a case in a **switch** statement. If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the execution of the innermost loop and start executing the next line of code after the block. ## Syntax The syntax for a **break** statement in C# is: break; ## Flowchart ![Image 5: break statement in C#](#) ## Example ## Example using System; namespace Loops { class Program { static void Main(string[] args) { /* local variable definition */ int a =10; /* while loop execution */ while(a 15) { /* terminate the loop using break statement */ break; } } Console.ReadLine(); } } } When the above code is compiled and executed, it produces the following result: a value: 10 a value: 11 a value: 12 a value: 13 a value: 14 a value: 15 [![Image 6: C# Loops](#) C# Loops](#)
← Csharp Continue StatementCsharp Nested Loops β†’