Use if, if-else, and nested if-else to create branching logic.
The `if` statement is the most fundamental control flow construct. It allows a program to make a decision based on a condition. The syntax is straightforward: `if (condition) { /* code to execute */ }`. The `condition` inside the parentheses is evaluated. If it resolves to `true`, the code block inside the curly braces is executed. If it resolves to `false`, the block is skipped, and the program continues with the next statement after the `if` block. To handle the case where the condition is false, you can add an `else` clause: `if (condition) { /* block A */ } else { /* block B */ }`. Here, if the condition is `true`, block A is executed; otherwise, block B is executed. This ensures that one of the two blocks will always run. For more complex scenarios involving multiple conditions, you can chain these statements using `else if`. This allows you to test a series of conditions in order. The first condition that evaluates to `true` will have its corresponding code block executed, and the rest of the chain will be skipped. A final `else` block can be added at the end to act as a default case, which runs if none of the preceding `if` or `else if` conditions were met. This structure is incredibly powerful for implementing logic, from simple checks to complex decision trees.