0

When and why should I use a nested if statement instead of an else if statement?

I've been having trouble figuring out when I should use a nest if statement instead of an else if statement

9th Nov 2018, 4:46 AM
StringJoe
StringJoe - avatar
4 Antworten
+ 13
Taste 2nd condition will be checked only if 1st condition is true , in case of && also.😅 //though there are some cases where we need to multiple nested if() . Example : like there are 3 if () & in 2nd if () we need to excute some more statements before the reaching to final inner most loop . that is why I typed "if U specifically want some statement(s) to excute if() certain conditions meet" //those all statement(s) are together in same inner most loop .☺
9th Nov 2018, 6:49 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 10
U don't need to do nesting if() statement , just simply used AND (&&) between condition if U specifically want some statement(s) to execute if certain conditions meet .☺👍 1)nesting if() , when more than 1 condition to be true for some statement(s) to execute . 2)nesed if else , when U want either of other statement(s) to execute if if () condition evaluates to false . //else execute 1st statement(s) only.
9th Nov 2018, 6:31 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
Yes but for some case nested if are needed for simpler code, or need to peform something before the second check I agree with using && but i disagree "dont need"
9th Nov 2018, 6:39 AM
Taste
Taste - avatar
+ 2
Nested if usually used when you need 2 condition to fullfil if(A) if(B) //A and B needs to be true if(C) // A and C needs to be true if(A) //if this true, B wont be executed else if(B) //Only one can be executed
9th Nov 2018, 5:42 AM
Taste
Taste - avatar