if Statement


There are two types of decision making statements in Java.

They are:
  • if statements
  • switch statements
The if Statement:

An if statement consists of a Boolean expression followed by one or more statements.

Syntax:

if(Boolean_expression)
{
  //Statements will execute if the Boolean expression is true
}

If the Boolean expression evaluates to true then the block of code inside the if statement will be executed.
If not the first set of code after the end of the if statement (after the closing curly brace) will be executed.

Example:

public class TestIf
{
  public static void main(String args[])
  {
     int i = 5;

     if( i < 10 )
     {
        System.out.print("This is if statement");
     }
  }
}


Popular posts from this blog

Naming Conventions

if..else..if Loader

Nested if..else Statement