369 TESLAKALVIYOGI
Page 25 of 30

Nested If

Condition inside condition with real-life example

</> logic
1

Concept Meaning

Nested if means an if condition written inside another if condition. The inner condition is checked only if the outer condition is true.

2

Real-Life Analogy

First check pass. If pass, then check distinction.

3

Expected Output

82 → Pass with Distinction
4

Common Mistake

Inner if does not run when outer if is false.

Same Logic • Different Syntax

Code in 4 Languages

JavaScript
let mark=82;
if(mark>=35){
 if(mark>=75) console.log("Pass with Distinction");
 else console.log("Pass");
}else console.log("Fail");
C++
int mark=82;
if(mark>=35){
 if(mark>=75) cout<<"Pass with Distinction";
 else cout<<"Pass";
}else cout<<"Fail";
Python
mark=82
if mark>=35:
    if mark>=75:
        print("Pass with Distinction")
    else:
        print("Pass")
else:
    print("Fail")
PHP
<?php
$mark=82;
if($mark>=35){
 if($mark>=75) echo "Pass with Distinction";
 else echo "Pass";
}else echo "Fail";
?>

Memory Tip

Outer if checks first. Inner if checks next.