If Branch The if branch executes a statement when a condition is true. In other words, a specific statement is executed if a condition is met. An if branch is a greatly utilized and indispensable control structure. The following is the syntax for the if branch:
Syntax if (condition) { statement(s); }
Syntax Details Argument if
Description Keyword that starts the if branch
condition
Boolean expression which results in a true or false result
{
An opening curly bracket
statement(s)
Statement that will be executed if the condition is true
;
Semi-colon completes the true statement
} A closing curly bracket Figure 4.1 – If Branch Syntax Details
The following example displays a message if the customer brings three extra customers to a sporting event:
public class ControlStructures { public static void main (String[] args)