Nested conditional. It is the case, when we have one (or more) if/else condition inside another if/else. For example:
if a > 2:
print("a is greater then 2")
else:
if a < 2:
print("a is less then 2")
else:
print("a is equal to 2")
Here the first if is checked first and in case the statement a>2 is not true, compiler goes to the first else. But here we have another if to be checked.
Chained conditional. It represents the same idea, but in more simple way of coding, using if/elif/else:
if a > 2:
print("a is greater then 2")
elif a < 2:
print("a is less then 2")
else:
print("a is equal to 2")
Here first the if statement is checked. If it is true, everething ends. If not, then elif statement a<2 is checked. Again, if it is true, this block finishes, if not - goes to else. There could be more then one elif statement. The output of later program is the same as of former one.
Comments
Leave a comment