The Best Technical Blog Ever

twitterrss

Branching Statements in java

There are three types of branching statements in java. They are,

  1. break
  2. continue
  3. return

The break Statement:

Break statement controls the flow of the program. It is used to stop the iterations in control statements. If you want to stop the loop at a specific point, you should use break keyword. It will stop the execution and transfers control to the line immediate outside of loop. The break keyword must be used inside any loop or a switch statement.


Syntax:
break;

Example:
break statement

The continue Statement:

Continue statement is used when we want to skip the rest of the statement in the body of the loop and continue with the next iteration of the loop. It continues the iteration when the conditional statement is true.


Syntax:
continue;

Example:
continue statement

The return Statement:

The return statement is used in methods to return a value and transfers the control back to the calling method. To use return, give the value of an expression after the return keyword. The data type of the returned value must match the type of the declared method. If the method is declared void, we can't return any value. In that case, use return that doesn't return a value.


Example:
return x++;
return;

Example:
return statement

Keypoints to remember in java

1. Java is a high level, robust, secured , platform independent and object oriented programming.... more info

Back to Basics:- Java Syntax

In this session, you are going to refresh some basic set of rules(java syntax), defining how a ... more info

Total Visits
Traffic feed status