Java TutorialLesson 14Free preview
Java If...Else
This lesson is part of Java · All levels
Summary
This lesson teaches decision making using if, if-else, if-else if, and nested if. A condition with a value of true will run a block of code under it, while else handles an unmet condition. Branching allows programs to react differently to different data.
Key points
- Use if to check one condition, else to alternate when the condition fails.
- A series of tiered conditions written with if... else if... else
- Parentheses () contains the condition, curly braces {} contains the code that is executed
- Blocks without curly braces only apply to one following statement
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.