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 Conditions
Go भाषा में Conditional Statements
Conditional Statements का उपयोग तब किया जाता है जब हमें किसी शर्त (condition) के आधार पर अलग-अलग कोड चलाने की आवश्यकता होती है।
Go में Conditions
एक condition का परिणाम हमेशा true या false होता है।
Go भाषा में निम्नलिखित comparison operators का प्रयोग किया जाता है:
- Less than:
< - Less than or equal:
<= - Greater than:
> - Greater than or equal:
>= - Equal to:
== - Not equal to:
!=
और Go में निम्नलिखित logical operators का भी प्रयोग किया जाता है:
- Logical AND:
&& - Logical OR:
|| - Logical NOT:
!
उदाहरण:
x > y x != y (x > y) && (y > z) (x == y) || z
Go में Conditional Statements के प्रकार:
- if – किसी शर्त के सही होने पर कोड चलाने के लिए।
- else – उसी शर्त के गलत होने पर कोड चलाने के लिए।
- else if – नई शर्त जांचने के लिए जब पहली गलत हो।
- switch – कई वैकल्पिक कोड ब्लॉकों में से एक को चलाने के लिए।
उदाहरण 1: if, else if, else
package main
import "fmt"
func main() {
x := 20
if x < 10 {
fmt.Println("x 10 से छोटा है")
} else if x == 10 {
fmt.Println("x 10 के बराबर है")
} else {
fmt.Println("x 10 से बड़ा है")
}
}
उदाहरण 2: switch स्टेटमेंट
package main
import "fmt"
func main() {
day := "monday"
switch day {
case "monday":
fmt.Println("सप्ताह की शुरुआत!")
case "friday":
fmt.Println("लगभग वीकेंड!")
default:
fmt.Println("सामान्य दिन")
}
}
switch के अंदर break स्वतः होता है,
इसलिए प्रत्येक case के बाद break लिखने की आवश्यकता नहीं है।