java2db

How to use if and if else control flow statement in java



The if else statement is used to execute a block of statements based on a test condition.If  the  particular test evaluates to true , entered into the if block ,otherwise executes else block.

Syntax:

 if(condition)
{
statements to execute
———————
———————
———————
———————
}
if(condition)
{
statements to execute
———————
}
else
{
statements to execute
———————
}
if(condition)
{
statements to execute
———————
}
else if(Condition)
{
statements to execute
———————
}//we can write more else if here
else
{
statements to execute
———————
}

if else control flow statement in java  Example for IF statement :

if else control flow statement in java  Example for IF ELSE  statement :

if else control flow statement in java  Example for  IF – ELSE IF – ELSE  statement :

Another Example for all the above statements :

Execution Result:

if else control flow statement in javaWe can check  multiple conditions with if – else if – else ladder.

if else control flow statement in javaThe opening and closing braces are optional, when the if or else block contains only one statement that need to be execute.

if else control flow statement in javaThrows an error if we use break or continue inside  the if else body .




Related Posts :
   [will not be published]



^ <