Difference b/w Break and continue statement
Using break statement,you can 'jump out of a loop' whereas by using continue statement, you can 'jump over one iteration' and then resume your loop execution.
Eg. Break Statement
- 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.ReadLine( “The number is”+i );
- }
- }
- }
- }
Output
The number is 0;
The number is 1;
The number is 2;
The number is 3;
Eg. Continue Statement
- using System;
- using System.Collections;
- using System.Linq;
- using System.Text;
-
- namespace continue_example {
- Class cntnu_stmt
- {
- public static void main(String [] args)
- {
- for( int i=0; i<=5; i++)
- {
- if ( i==4) {
- continue;
- }
- Console.ReadLine( “The number is”+i);
- }
- }
- }
- }
Output
The number is 0;
The number is 1;
The number is 2;
The number is 3;
The number is 5;