![]() |
VOOZH | about |
In Java, an if statement is the simplest decision-making statement. It is used to execute a block of code only if a specific condition is true. If the condition is false, the code inside the if block is skipped.
Syntax:
if (condition) {
// Statements executed if the condition is true
}
Example: with Curly Braces
10 is less than 15 Outside if-block
Explanation:
Example: without Curly Braces
i is positive This statement runs regardless of if condition
Explanation:
Flowchart if statement: