[an error occurred while processing this directive]

The if Keyword  

                         

The if is a keyword, which is used to perform the selection statement. It is used to execute the statements after evaluating the condition specified in it as true. When the condition is true, the code in the "if" block is executed. When false, the code in the if block is skipped. It starts a branching statement.

It is used to define a statement or block of statements that are executed in case, the test condition specified by the if keyword evaluates to true. When the if condition evaluates to true, the code after the if block is executed.

The if is a java keyword that may not be used as identifiers i.e. you cannot declare a variable or class with this name in your Java program. If an optional block is defined with the else keyword, then the else block is executed when the test evaluates to false.

The following shows the format of the if selection Construct syntax. 

if (<condition>){

 <statements1>

<statements2>

}

if (condition){

<statements>

}

else{

<statements>

} 

 Here is an example of if keyword: 

class IfDemo{
  public static void main(String[] args){

 

     if (x > 1)
     System.out.println("Greater than 1");
      if (x < 1)
     System.out.println("Less than 1");

    }

}

 

In the above example if we declare int x = 1, the statements will show some of the valid boolean expressions to the if statement.

                         

[an error occurred while processing this directive]