Branching Statements In Java

Branching statements are used to change the normal flow of execution in a program.

  • break Statement
  • continue Statement
  • return Statement
break Statement

The break statement is used to exit a loop or switch block prematurely.

Output
i = 0
i = 1
i = 2
i = 3
i = 4
continue Statement

The continue statement is used to skip the current iteration of a loop and continue with the next iteration.

Output
i = 0
i = 1
i = 3
i = 4
return Statement

The return statement is used to exit a method and optionally return a value.

Output
Sum = 15