Lessons
Go Introduction
Go Get Started
Go Syntax
Go Comments
Go Variables
- Declare Variables
- Go में Variables का परिचय
- Go में Multiple Variable Declaration
- Variable Naming Rules (नामकरण के नियम)
Go Constants
Go Output
Go Data Types
- Basic Data Types
- Go Boolean Data Type (बूलियन डेटा प्रकार)
- Go Integer Data Types
- Go Float Data Types
- Go String Data Type
Go Arrays
Go Slices
Go Operators
- Go Operators
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
- Bitwise Operators
Go Conditions
Go Switch
Go Loops
Go Functions
Go Struct
Go Maps
Project Structure
Go Nested if Statement
Go भाषा में Nested if Statement
Nested if statement का मतलब होता है कि एक if के अंदर दूसरा if स्टेटमेंट रखा गया हो।
इसका उपयोग तब किया जाता है जब किसी condition के अंदर एक और अतिरिक्त शर्त को जांचना हो।
सिंटैक्स (Syntax)
if condition1 {
// यह कोड तब चलेगा जब condition1 सही हो
if condition2 {
// यह कोड तब चलेगा जब दोनों condition1 और condition2 सही हों
}
}
उदाहरण:
नीचे दिए उदाहरण में दिखाया गया है कि nested if कैसे काम करता है:
package main
import ("fmt")
func main() {
num := 20
if num >= 10 {
fmt.Println("Num is more than 10.")
if num > 15 {
fmt.Println("Num is also more than 15.")
}
} else {
fmt.Println("Num is less than 10.")
}
}
Result:
Num is more than 10. Num is also more than 15.
उदाहरण का स्पष्टीकरण:
इस उदाहरण में सबसे पहले प्रोग्राम चेक करता है कि क्या num 10 से बड़ा या बराबर है।
यह शर्त सही है क्योंकि num = 20 है, इसलिए "Num is more than 10." प्रिंट होता है।
इसके बाद अंदर वाला if चेक करता है कि क्या num 15 से बड़ा है।
यह भी सही है, इसलिए "Num is also more than 15." प्रिंट होता है।