break continue statements

break continue statements

break

The break statement in C, C++ and Java terminates the statement sequence. We saw it in the Switch case as well. In Java, we can use break as,

  • break in switch
  • break as goto
  • break outside label

Let us first see the syntax,

Syntax

Example

Let us see an example to learn more about break statement in Java,

Output

The following is the output,

break statement in Java

break in switch

Let us see an example to learn about the usage of break in switch statement in Java,

The following is the output,

Java Break in Switch Statement

break as goto

Let us see an example to learn about the usage of break as goto in Java,

The following is the output,

Break statement as Goto in Java

continue

The continue statement transfers control to the conditional expression and jumps to the next iteration of the loop.

Syntax

Example

The following is an example showing the usage of continue statement,

The following is the output,

continue statement in Java

continue as goto

Let us learn about how to work with continue statement as goto in Java,

The following is the output,

continue as goto in Java

In this lesson, we learned how to work with loops in Java. We saw the implementation of while loop, do-while loop, for loop, break statement and continue statement.

Loops in Java
Arrays in Java
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create free tutorials for all.

No Comments

Post A Comment