subjects

Dropdown Menu

Tuesday 26 April 2022

Nested If

 To evaluate multiple conditions we use nested if statement. The general form is

Syntax

if test condition1:

        if test condition2:

                statement1

        else:

                statement2

else:

        statement3

From the above syntax if the condition1 is true control transfers to condition2 when it is true statement 1 executes, oterwise statement 2 will be executed.If the condition1 itself false the control will be transferred to else part and statement3 will be executed.