(Go mailing list problem record 2)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

(Go mailing list problem record 2)

Compiling error when using struct literal on for loop

Compile the problem, the code is as follows, the code inside the comment is the compile error

 PackageMainimport"FMT"typet struct {Field int}func (T T) Next () t {returnT{t.field+1}}func Main () {/* GotErrorAtNext  forStatement:prog.go: -: syntaxError: unexpected {atEndof statement Prog.go: -: syntaxError: Non-declaration statement outside function body for t : = t{1}; T.field < 10; t = t.next()     {FMT. Println (t)} *//This is fine t2: = t{1} for; T2. Field <Ten; t2 = T2. Next () {fmt. Println (T2)}}

Although it may be written in theory and need support, but this compilation problem is not serious to go language has to be corrected immediately, and for parsing, there is really a lot of difficulty here.

Of course there are circumvention methods, the code is written so that you can.

func main() {    for t := (T{1}); t.Field < 10; t = t.Next() {        fmt.Println(t)    } }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.