The if statement, if..else statement, and if..elif..else statement have all been covered in prior tutorials. We will discover how to nest these control statements in this tutorial.
The nesting of control statements occurs when an if statement (or if..else or if..elif..else) is contained inside another if statement (or if..else or if..elif..else).
Example of a nested if..else statement
In this case, an if statement is contained within a block of if..else statements. We must check several conditions as a result of nesting control statements.
num = -99 if num > 0: print("Positive Number") else: print("Negative Number") #nested if if -99<=num: print("Two digit Negative Number")
Negative Number Two digit Negative Number