Concept
The if statement is used to create a decision structure, which allows a program to have more than one path of execution. The if statement causes one or more statements to execute only when a boolean expression is true.
Syntax
Here is the general format of the if statement:
if (BooleanExpression)
statement;
Logic
How if statement works?
The if condition that appears inside the parentheses must be a boolean expression. A boolean expression may be either true or false. If it is true, the very next statement is executed. Otherwise, it is skipped. The statement is conditionally executed because it executes only under the condition that the expression in the parentheses is true.
Example (IfDemo.java)

No comments:
Post a Comment