Home > Backend Development > Golang > Simple Bengali explanation of 25 keywords of Go Programming Language

Simple Bengali explanation of 25 keywords of Go Programming Language

DDD
Release: 2025-01-18 20:02:13
Original
544 people have browsed it

Go Programming Language-এর ২৫টি কিওয়ার্ডের সহজ বাংলা ব্যাখ্যা

These keywords in Go (Golang) are used to manage various features and rules of the language.

1. break

  • Function: is used to exit a loop or switch statement.
  • Example:
<code class="language-go">for i := 0; i < 10; i++ {
    if i == 5 {
        break // 退出循环
    }
    fmt.Println(i)
}</code>
Copy after login
Copy after login
Copy after login

2. case

  • Function: is used to perform operations based on a specific value in a switch statement.
  • Example:
<code class="language-go">switch day := "Monday"; day {
case "Monday":
    fmt.Println("一周的开始")
case "Friday":
    fmt.Println("周末快到了!")
}</code>
Copy after login
Copy after login
Copy after login

3. chan

Chan or channel is used to exchange data between goroutines in Go programs. This is a way to manage program concurrency.

  • Function:

Communication between goroutines:

  • Data can be sent from one goroutine to another through a channel.
  • It is synchronous, which means when one goroutine sends data, the program will wait until another goroutine receives the data.

Data sharing:

  • Share data between goroutines through channels.

When to use?

When multiple goroutines are running and data needs to be exchanged between them. For example: communication between producers and consumers.

  • Example:
<code class="language-go">for i := 0; i < 10; i++ {
    if i == 5 {
        break // 退出循环
    }
    fmt.Println(i)
}</code>
Copy after login
Copy after login
Copy after login

Why use?

  • Conveniently share data between goroutines.
  • Avoid deadlocks or race conditions.
  • Improve program performance.

4. const

  • Function: is used to declare constant or immutable variables.
  • Example:
<code class="language-go">switch day := "Monday"; day {
case "Monday":
    fmt.Println("一周的开始")
case "Friday":
    fmt.Println("周末快到了!")
}</code>
Copy after login
Copy after login
Copy after login

5. continue

  • Function: is used to skip the current iteration of the loop and continue with the next iteration.
  • Example:
<code class="language-go">package main

import "fmt"

func main() {
    c := make(chan int) // 创建 channel

    // 启动一个 goroutine
    go func() {
        c <- 1 // 发送数据到 channel
    }()

    fmt.Println(<-c) // 从 channel 接收数据
}</code>
Copy after login
Copy after login

6. default

  • Function: is used to perform operations when there is no case match in the switch statement.
  • Example:
<code class="language-go">const pi = 3.14</code>
Copy after login
Copy after login

7. defer

  • Function: is used to perform specific actions at the end of a function.
  • Example:
<code class="language-go">for i := 0; i < 10; i++ {
    if i == 5 {
        continue // 跳过 i == 5 的迭代
    }
    fmt.Println(i)
}</code>
Copy after login
Copy after login

8. else

  • Function: is used to add an optional condition to the if statement.
  • Example:
<code class="language-go">switch value := 3; value {
case 1:
    fmt.Println("一")
default:
    fmt.Println("默认情况")
}</code>
Copy after login

9. fallthrough

  • Function: is used to continue from one case to the next case in a switch statement.
  • Example:
<code class="language-go">defer fmt.Println("这将最后运行")
fmt.Println("这将首先运行")</code>
Copy after login

10. for

  • Function: is used to create loops.
  • Example:
<code class="language-go">if x > 10 {
    fmt.Println("大于 10")
} else {
    fmt.Println("小于或等于 10")
}</code>
Copy after login

11. func

  • Function: is used to create functions.
  • Example:
<code class="language-go">switch value := 1; value {
case 1:
    fmt.Println("情况 1")
    fallthrough
case 2:
    fmt.Println("情况 2")
}</code>
Copy after login

12. go

  • Function: is used to start goroutine.
  • Example:
<code class="language-go">for i := 0; i < 10; i++ {
    fmt.Println(i)
}</code>
Copy after login

13. goto

  • Function: is used to jump to a specific tag in the program.
  • Example:
<code class="language-go">func greet(name string) {
    fmt.Println("你好", name)
}</code>
Copy after login

14. if

  • Function: is used to check conditions.
  • Example:
<code class="language-go">go greet("世界")</code>
Copy after login

15. import

  • Function: used to import other packages.
  • Example:
<code class="language-go">goto End
fmt.Println("这将被跳过")
End:
    fmt.Println("程序结束")</code>
Copy after login

16. interface

  • Function: is used to define data types or methods.
  • Example:
<code class="language-go">if x > 0 {
    fmt.Println("正数")
}</code>
Copy after login

17. map

  • Function: is used to store key-value pairs.
  • Example:
<code class="language-go">import "fmt"</code>
Copy after login

18. package

  • Function: is used to organize code.
  • Example:
<code class="language-go">type Shape interface {
    Area() float64
}</code>
Copy after login

19. range

  • Function: is used to process items in a loop.
  • Example:
<code class="language-go">m := map[string]int{"one": 1, "two": 2}</code>
Copy after login

20. return

  • Function: is used to return a value from a function.
  • Example:
<code class="language-go">package main</code>
Copy after login

21. select

  • Function: is used to read data from channel.
  • Example:
<code class="language-go">for i := 0; i < 10; i++ {
    if i == 5 {
        break // 退出循环
    }
    fmt.Println(i)
}</code>
Copy after login
Copy after login
Copy after login

22. struct

  • Function: Used to create custom data types.
  • Example:
<code class="language-go">switch day := "Monday"; day {
case "Monday":
    fmt.Println("一周的开始")
case "Friday":
    fmt.Println("周末快到了!")
}</code>
Copy after login
Copy after login
Copy after login

23. switch

  • Function: Used to check multiple conditions.
  • Example:
<code class="language-go">package main

import "fmt"

func main() {
    c := make(chan int) // 创建 channel

    // 启动一个 goroutine
    go func() {
        c <- 1 // 发送数据到 channel
    }()

    fmt.Println(<-c) // 从 channel 接收数据
}</code>
Copy after login
Copy after login

24. type

  • Function: Used to create new types.
  • Example:
<code class="language-go">const pi = 3.14</code>
Copy after login
Copy after login

25. var

  • Function: is used to declare variables.
  • Example:
<code class="language-go">for i := 0; i < 10; i++ {
    if i == 5 {
        continue // 跳过 i == 5 的迭代
    }
    fmt.Println(i)
}</code>
Copy after login
Copy after login

Please note that the code examples have been modified to be more accurate and easier to understand. The translation should try to maintain the style and tone of the original text.

The above is the detailed content of Simple Bengali explanation of 25 keywords of Go Programming Language. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template