The break statement terminates the execution of the nearest enclosing loop. After termination of the loop or switch body, control passes to the statement that follows the terminated statement.
Flowchart of break:
using System;
using System.Collections;
using System.Linq;
using System.Text;
namespace break_example
{
Class brk_stmt
{
public static void main(String[] args)
{
for (int i = 0; i <= 5; i++)
{
if (i == 4)
{
break;
}
Console.WriteLine("The number is " + i);
Console.ReadLine();
}
}
}
}
Output:
The number is 0; The number is 1; The number is 2; The number is 3;
continue statement:
We can terminate an iteration without exiting the loop body using the continue keyword. When continue (jump statement) execute within the body of the loop, all the statements after the continue will be skipped and a new iteration will start. In other words, we can understand that continue causes a jump to the end of the loop body.
Flowchart of continue:
using System;
using System.Collections;
using System.Linq;
using System.Text;
namespace continue_example
{
Class cntnu_stmt
{
public static void main(String[] {
for (int i = 0; i <= 5; i++)
{
if (i == 4)
{
continue;
}
Console.WriteLine(“The number is "+ i);
Console.ReadLine();
}
}
}
}
Output:
The number is 1;
The number is 2;
The number is 3;
The number is 5;
break statement:
The break statement terminates the execution of the nearest enclosing loop. After termination of the loop or switch body, control passes to the statement that follows the terminated statement.
Flowchart of break:
Output:
The number is 0;
The number is 1;
The number is 2;
The number is 3;
continue statement:
We can terminate an iteration without exiting the loop body using the continue keyword. When continue (jump statement) execute within the body of the loop, all the statements after the continue will be skipped and a new iteration will start. In other words, we can understand that continue causes a jump to the end of the loop body.
Flowchart of continue:
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer