Skip to content

Instantly share code, notes, and snippets.

@tevjef
Last active November 30, 2016 23:24
Show Gist options
  • Save tevjef/c5e1abe271742910f3dc5289f9aeef38 to your computer and use it in GitHub Desktop.
Save tevjef/c5e1abe271742910f3dc5289f9aeef38 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
structArr()
structLiteral()
}
type myStruct struct { str string }
func structArr() {
for i := []myStruct{"a", "b", "c", "d"}; len(i) > 0; i = i[:len(i)-1] {
fmt.Println(i)
}
}
func structLiteral() {
// fails to compile. according to the spec composite literals are not allowed in init block
for i := myStruct{"abcd"}; len(i) > 0; i = i[:len(i)-1] {
fmt.Println(i)
}
}
@tevjef
Copy link
Author

tevjef commented Nov 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment