Nested ifs Assignment Help

Assignment Help: >> Elements of Java - Nested ifs

Nested ifs

A nested if is an if statement which is the goal of another if or else. Nested ifs are extremely common in programming. Whenever you nest ifs, the major thing to remember is that an else statement always refers to the nearest if statement which is in the similar block as the else and which is not already related within an else. Here is an instance.

if (i ==10 ) {

if (j< 20) a=b;

if (k>100) c=d; / / this if is

else a =c;        / / related along with this else

}

else a = d ;     / / this else refers to if (i == 10)

As the comments denotes, the last else is not related with if (j<20,) since it is not in the similar block (even by it is the nearest if without an else.) relatively, the last else is related along with if (i==10). The inner else refers to if (k>100,) since it is the closes if in the similar block.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd