4:31 am - Wednesday September 26, 2018

Control Flow Statements in java with Example Program

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Control Flow Statements

Control Statements:

The control statements in java are as same as C and C++.

  • if
  • if-else
  • if-else if
  • switch
  • break
  • continue
  • return

if Statement:

if statement is used to test the condition. The syntax for if condition is,

if( test condition)

{

Block of statements

…….

………

}

if-else statement:

If-else statement is used for test condition to check whether the statement is true or false. Depending upon the condition, the control statement exists.  The syntax for if-else statement is,

if ( test condition)

{

Block of statements…

…………….

………………

}

else

{

Block of statements….

………….

}

if-else if statement:

if-else if statement is used for more than one test condition.

The syntax for if-else if condition is,

if (test condition)

{

Block of statements…

……………..

}

else if( test condition)

{

Block of statements….

………….

}

else

{

…..

}

Switch Statement:   

The body of the switch statement is known as switch block. The switch statement labeled with one or more case statement and default statement. It evaluates the expression then executes all the statements follow the matching the case label.

 

switch (operator)

{

case 1:

Block of statements;

break       ;

case 2:

Block of statements;

break;

….

….

….

case n:

Block of statements;

break;

default:

Block of statements;

exit;

Break Statement:

                Break statement is used to exit from the loop. Break statement is a branch statement used at the end of each switch case statement. It is used to end up the switch statement or iteration loop. The syntax is,

<break statement>

break;

Continue Statement:

The continue statement can be used in any of the loop structures. It discontinues the current iteration of the current control statement and begins the next iteration. The syntax of continue statement is,

continue;

return statement:

        The return statement is used in end method execution and for returning the value. A value return by the method is written after the keyword. The return statement should not include an expression in void functions. The syntax of return statement is,

retutn;

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply