Break and continue statement in java

break and continue are java keywords to skip control flow statements depending on certain condition.

break and continue have 2 forms, labeled and unlabeled

Break

An unlabeled break statement terminates the innermost switch, for, while, or do-while statement, but a labeled break terminates an outer statement.

Unlabeled break statement usage

OutPut

I: 1 2 

labeled break statement usage

refer Exit from nested for loop

Continue

The continue statement skips the current iteration of a for, while , or do-while loop, but a labeled continue statement skips the current iteration of an outer loop marked with the given label.

Unlabeled continue statement usage

OutPut:

I: 1 2 4 5 

Labeled continue statement usage

OutPut:

Odd numbers are:
3
33
73
5

Content posted is based on learning or working experience, Share the post with others if find useful, Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

Leave a Reply

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

%d bloggers like this: