The if Statement

if Statements

The if statement is the most basic of all the control flow statements, the statements will execute when the condition checked true.

Syntax 1: One Statement without opening brace and closing brace

if (Expression)

Statement 1;

Example 1:

if (score>=50)

System.out.println(“Passed”);

Syntax 2: More than one Statements must be using with opening brace and closing brace

if (Expression)

{

Statement 1;

Statement 2;

Statement 3;

Statement N;

}

Example 2:

if (score<50)

{

System.out.println(“Failed”);

System.out.print(“Sorry !!!”);

}

Leave a comment

Your email address will not be published. Required fields are marked *

18 − 14 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.