369 TESLAKALVIYOGI
Page 23 of 30

If Else Statement

Pass/fail example in JS, C++, Python, PHP

</> logic
1

Concept Meaning

If else chooses between two actions. If condition is true, if block runs. Otherwise, else block runs.

2

Real-Life Analogy

If mark is 35 or more, pass. Otherwise, fail.

3

Expected Output

Pass or Fail
4

Common Mistake

Else does not need another condition; it handles the remaining case.

Same Logic • Different Syntax

Code in 4 Languages

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

Memory Tip

Condition true → first action. False → second action.