About Author-> This code has been written by Mr. Manish Gupta(still studying in BCA) for purpose will be utilizing in future time.(If need) .
Protection or security : Here, whatever else has been written all are compiled and run
by me(ie. Manish). If you face any type of problem
during compilation and anything else related to this coding . Then,
You can mail me at manishnips2018@gmail.com (I'll try to give respond as soon as possible).
Source : Internet
Quotation for Today: learning is Priceless.
let's enjoy_>
Transfer Statement
// break;
-> We can use break; statement in the following places:
1. inside switch statement-> to stop fall stop fall through.
Program.
class Test
{
public static void main(String [] args)
{
int x=0;
switch(x)
{
case 0:
System.out.println(0);
case 1:
System.out.println(1);
break;
case 2:
System.out.println(2);
default:
System.out.println("def");
}
}
}
2. Inside loop -> To break loop execution based on some condition.
class Test
{
public static void main(String [] args)
{
for(int i=0;i<10;i++)
{
if (i==5)
break;
System.out.println(i);
}
}
}
O/p:
0
1
3
4
3. inside labeled block -> To break execution based on some condition.
class Test
{
public static void main(String [] args)
{
int x=10;
l1:
{
System.out.println("begin");
if(x==10)
break;
System.out.println("end");
}
System.out.println("Hello");
}
}
-> These are the only places, where we can use break; statement. If we are using anywhere else,
we'll get compile time error saying:
break outside switch or loop
example: */
class Test
{
public static void main(String [] args)
{
int x=10;
if(x==10)
break;
System.out.println("Hello");
}
}
// break;
-> We can use break; statement in the following places:
1. inside switch statement-> to stop fall stop fall through.
Program.
class Test
{
public static void main(String [] args)
{
int x=0;
switch(x)
{
case 0:
System.out.println(0);
case 1:
System.out.println(1);
break;
case 2:
System.out.println(2);
default:
System.out.println("def");
}
}
}
2. Inside loop -> To break loop execution based on some condition.
class Test
{
public static void main(String [] args)
{
for(int i=0;i<10;i++)
{
if (i==5)
break;
System.out.println(i);
}
}
}
O/p:
0
1
3
4
3. inside labeled block -> To break execution based on some condition.
class Test
{
public static void main(String [] args)
{
int x=10;
l1:
{
System.out.println("begin");
if(x==10)
break;
System.out.println("end");
}
System.out.println("Hello");
}
}
-> These are the only places, where we can use break; statement. If we are using anywhere else,
we'll get compile time error saying:
break outside switch or loop
example: */
class Test
{
public static void main(String [] args)
{
int x=10;
if(x==10)
break;
System.out.println("Hello");
}
}