Java program to show use of break/continue statement

This java program show use of break statement in for loop.

  • break is used to¬†prematurely¬†exit the loop.


[java]
class BreakDemo
{
public static void main(String args[]){

for (int i=1;i<=10;i++)
{
System.out.println("Value = " + i);

if(i==5)

{
break;
}
}
}
}

[/java]

This java program show use of continue statement in for loop.

continue is oppsite of break instead of stopping the loop it skipt some parts of loop


[java]

class ContDemo
{
public static void main(String args[]){

for (int i=1;i<=10;i++)
{

if(i==5)
{
continue;
}
System.out.println("Value = " + i);
}
}
}

[/java]

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.