Break and continue are keywords used to control the flow of execution in loops and switch statements.
Example usage of break statement in a for loop:
for (int i = 1; i <= 10; i++)
{
if (i == 5)
{
break; // terminate the loop if i is equal to 5
}
Console.WriteLine(i);
}
Example usage of continue statement in a while loop:
int i = 0;
while (i < 5)
{
i++;
if (i == 3)
{
continue; // skip the current iteration when i is equal to 3 }
Console.WriteLine(i);
}
Note that break and continue statements can be used with for, while, do-while loops, as well as with switch statements.
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.