Break and Continue |
Code:
class breakandcontinue//for more program please visit www.programtubenotes.blogspot.in
{
public static void main(String args[])
{
// Illustrating break statement (execution stops when value of i becomes to 4.)
System.out.println("Break Statement\n....................");
for(int i=1;i<=5;i++)
{
if(i==4) break;
System.out.println(i);
}
// Illustrating continue statement (execution skipped when value of i becomes to 1.)
System.out.println("Continue Statement\n....................");
for(int i=1;i<=5;i++)
{
if(i==1) continue;
System.out.println(i);
}
}
}
{
public static void main(String args[])
{
// Illustrating break statement (execution stops when value of i becomes to 4.)
System.out.println("Break Statement\n....................");
for(int i=1;i<=5;i++)
{
if(i==4) break;
System.out.println(i);
}
// Illustrating continue statement (execution skipped when value of i becomes to 1.)
System.out.println("Continue Statement\n....................");
for(int i=1;i<=5;i++)
{
if(i==1) continue;
System.out.println(i);
}
}
}
Output:
Break Statement
....................
1
2
3
Continue Statement
....................
2
3
4
5
....................
1
2
3
Continue Statement
....................
2
3
4
5
<<Previous Page Download Code Next Page>>
Related JAVA Programs:
- Write a JAVA program to print "Hello World".
- Write a JAVA program to find sum of all integer greater than 100 and less than 200, that are divisible by 5.
- Write a JAVA program to show how method overriding helps in dynamic method dispatch.
- Write a JAVA program to Serach and Delete a specific element from an integer array.
- Write a JAVA program to illustrate how super keyword is used to call the parent class constructor within the child class.
- Write a JAVA program illustrating parameterized constructor.
- Write a JAVA program to create and access a user defined packages.
- Write a JAVA program to calculate the length of a string.
- Write a JAVA program to findout the number of Vowels present in the input string.
- JAVA Program that implements the Concept of Encapsulation.