Conditional Statements in Java

Level : Beginner
Mentor: Shailendra Chauhan
Duration : 00:02:00

What are Conditional Statements?

Conditional statements allow you to make decisions based on certain conditions. Conditions specify a set of decision-making statements with Boolean expressions. Boolean expressions are evaluated as true or false.

Types of Conditional Statements in Java

There are 4 types of conditional statements in Java:

  1. If statements in Java
  2. If else statements in Java
  3. Ladder statements or If Else If statements
  4. Switch statements


If Statement

The If statement consists of a Boolean expression that is evaluated to a Boolean value. If the value is True, the block is run; otherwise, the next statement is executed.


If-Else Statement

If-else statements consist of two statements: if and else. When the expression in the if-statement is true, the if block is run; otherwise, the else block is executed.


If-Else-If statement or ladder

The If-Else-If statement, sometimes known as a ladder, tests a set of conditions using successive if-else if-else statements. The statement that meets the outcome will be performed. When no condition meets the desired result, the default else statement is executed.


Switch Statement

Switch statements evaluate a set of conditions using one or more cases that are compared to the switch expression. The case that meets the result will be performed. When no cases match the result, the default case is executed.

Self-paced Membership
  • 24+ Video Courses
  • 825+ Hands-On Labs
  • 400+ Quick Notes
  • 125+ Skill Tests
  • 10+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this