-
Key Features and
Create a new project in Visual Studio 2022 - Naming Standards & Comments
- Data Types
- Variables and Constant Variable
- Conditional Statement
- Switch Conditional Statement
- Arithmetic, Comparison, Assignment and Logical Operators
- For, While and Do While Loops
- Importance of Break and Continue Keywords
- Strings and Important String Methods
- Single Dimensional Array
- Multi Dimensional Array
- Methods and Method Overloading
- Math Class and Functions
- Casting and Type Conversions
- Class and Objects
- Constructor, Parameter less and Parameterized Constructor
- Single, Multi level and Hierarchical Inheritance
- Compile Time Polymorphism, Method and Operator Overloading
- Run-time Polymorphism and Importance of base keyword
- Abstract Class and Method
- Interface and Multiple Inheritance through Interfaces
Agenda
- Break Statement in C#
- Continue Statement in C#
Break Statement in C#
- Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.
- C# supports break and continue control statements.
- When a break statement is encountered inside a loop, the loop is immediately terminated, and the program control resumes at the next statement following the loop.
- The C# break is used to break loop or switch statement. It breaks the current flow of the program at specified condition. In case of inner loop, it breaks only inner loop.
Syntax:
jump-statement;
break;
Continue Statement in C#
- The continue keyword can be used in any of the loop control structures. It will stop the current iteration and pass the control to the next iteration by going back to the beginning of the loop.
- The purpose of writing a continue statement in C# code is to skip the current iteration of a loop, like for, while and do-while.
- The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
Syntax:
jump-statement;
break;
for (int i = 0; i < 5; i++)
{
if (i == 2)
{
break;
}
Console.WriteLine(i);
}
for (int i = 0; i < 5; i++)
{
if (i == 2)
{
continue;
}Console.WriteLine(i);
}
int i = 10;
while (i > 2){
Console.WriteLine(i);
i--;
if (i == 6){
break;
}
}
int i = 10;
while (i > 2)
{
Console.WriteLine(i);
i--;
if (i == 6){
continue;
}
}
int i = 10;
do
{
Console.WriteLine(i);
i--;
if (i == 6){
break;
}
} while (i > 2);
int i = 10;
do
{
if (i == 6)
{
i = i - 1;
continue;
}Console.WriteLine(i);
i--;
} while (i > 2);
Console.ReadKey();
for (int outer = 0; outer < 5; outer++)
{
for (int inner = 0; inner < 5; inner++)
{
if (inner > outer)
{
break;
}
Console.Write($"{inner} ");
}
Console.WriteLine();
}