if / else
Executes code based on a condition.
Syntax
if (condition) { } else { }Description
Condition in parentheses, blocks in { }. Intermediate conditions with else if.
Example
Loading editor…
Expected output
Passed
When to use?
Flow branching.
Common mistakes
- ⚠️ String equality is checked with .equals(), not ==.