Important Notice:

Nested if Statement

Nested if Statement

26 views 1 min read

Nested if Statement (नेस्टेड if स्टेटमेंट)

हिंदी व्याख्या: जब एक if स्टेटमेंट के अंदर दूसरा if या if-else हो तो उसे Nested if कहते हैं। यह तब उपयोगी होता है जब एक शर्त सही होने के बाद दूसरी शर्त भी चेक करनी हो।

Syntax:-
 

if (condition1)
{ if (condition2)
{ // दोनों शर्तें सही हों तो }
else
{ // condition1 सही, condition2 गलत } } else { // condition1 गलत }

 
 

उदाहरण:

JavaScript
 

let age = 20; let hasLicense = true;

if (age >= 18) { if (hasLicense) { console.log("You can drive.");

 } else { console.log("You are adult but no license."); }

 } else { console.log("You are too young to drive."); }

Output:-

You can drive.

 

English Explanation: Nested if means an if statement inside another if statement. It is used when we need to check a second condition only after the first one is true.

Related Notes