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 if statement
Go भाषा में if Statement
if statement का उपयोग तब किया जाता है जब किसी condition (शर्त) के सही होने पर कोई कोड ब्लॉक चलाना हो।
सिंटैक्स (Syntax)
if condition {
// यदि condition सही है तो यह कोड चलेगा
}
if हमेशा छोटे अक्षरों (lowercase) में लिखा जाता है।
अगर आप If या IF लिखते हैं तो यह error देगा।
उदाहरण 1:
नीचे दिए उदाहरण में हम जाँचते हैं कि क्या 20, 18 से बड़ा है। अगर यह सही है, तो एक संदेश प्रदर्शित होता है।
package main
import ("fmt")
func main() {
if 20 > 18 {
fmt.Println("20 is greater than 18")
}
}
उदाहरण 2: Variables के साथ
package main
import ("fmt")
func main() {
x := 20
y := 18
if x > y {
fmt.Println("x is greater than y")
}
}
उदाहरण का स्पष्टीकरण:
ऊपर दिए गए उदाहरण में हमने दो वेरिएबल्स x और y का उपयोग किया है।
यह जांचने के लिए कि क्या x y से बड़ा है (यानी > ऑपरेटर के साथ)।
क्योंकि x की वैल्यू 20 और y की वैल्यू 18 है, और हमें पता है कि 20, 18 से बड़ा है,
इसलिए प्रोग्राम स्क्रीन पर यह संदेश दिखाएगा:
"x is greater than y"