Learn Pain Less

HomeOur TeamContact
Java
Nested if statement in java
Pawneshwer Gupta
Pawneshwer Gupta
February 17, 2015
1 min
Nested if statement in java
if (cond1){
if (cond2){
if (cond3){

Is nested because you have conditions evaluated within other conditions, that is, dependent on previous conditions. If you want to be literal about it, the scope of cond2 in the second case is literally nested in the scope of cond1. This is not true in the first form. where the else part is optional. And you have effectively nested an if into the else part of the outer if else, even if the formatting (and maybe semantics) suggests it differently. But in fact it boils down to the exact definition of “nested if”, and I do not think there is a generally accepted one This is an if statement:

if (condition1) {
// ...
}

This is a nested if statement:

if (condition1) {
// ...
if (condition2) {
// ...
}
// ...
}

This is an if-else statement:

if (condition1) {
// ...
} else {
// ...
}

This is a chained if-else statement:

if (condition1) {
// ...
} else if (condition2) {
// ...
}

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Tags

startnested if

Share


Pawneshwer Gupta

Pawneshwer Gupta

Software Developer

Pawneshwer Gupta works as a software engineer who is enthusiastic in creating efficient and innovative software solutions.

Expertise

Python
Flutter
Laravel
NodeJS

Social Media

Related Posts

Working with Files, Folders java
Working with Files, Folders java
March 25, 2015
1 min
Learn Pain Less  © 2024, All Rights Reserved.
Crafted with by Prolong Services

Quick Links

Advertise with usAbout UsContact Us

Social Media