Continue and Break Statement in C# (Console Application)
--------------------------------------------------------------------------------------------------------------------------
Difference b/w Continue and Break statement :-
Continue statement :- A Continue statement jumps out of the current loop condition and jumps back to the starting of the loop code.
Break statement :- A Break statement breaks out of the loop at the current point or we can say that it terminates the loop condition.
----------------------------------------------------------------------------------------------------------------------------------
Source Code :-
-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Continue_Break_Prog
{
class Program
{
static void Main(string[] args)
{
int x;
for (x = 0; x <= 10; x++)
{
if (x == 5)
continue;
if (x == 8)
break;
Console.WriteLine("Number =" + x);
}
Console.ReadLine();
}
}
}
-
Result :-
Number = 0
Number = 1
Number = 2
Number = 3
Number = 4
Number = 6
Number = 7
-----------------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment