LoginSignup
1
0

More than 3 years have passed since last update.

眺めて覚えるGo言語 その11 無名関数(Anonymous function)

Posted at

では、眺め用サンプルコード

f11.go
package main
import (
    "fmt"
)
func main() {
    h1:=func(a string)(string){ return "<h1>"+a+"</h1>"}
    fmt.Println(h1("Topics"))
}
実行結果
>go run f11.go
<h1>Anonymous</h1>

名無しの関数

f12.go
package main

import (
    "fmt"
)

func main() {
    func(){
        for i:=0;i<10;i++{
            fmt.Println("i=",i)
        }
    }()
}

実行結果
>go run f12.go
i= 0
i= 1
i= 2
i= 3
i= 4
i= 5
i= 6
i= 7
i= 8
i= 9
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0