chatgpt is saying that for vary with integer works totally different, like it’s transformed to an iterable sort first, (to string) and iterates over rune ‘5’ solely as soon as, however once I run it in playground, it’s working like I’d have written:
for i := 0; i
fmt.Println(“Hiya!”)
}
Is that this a brand new function added in latest go replace mine is working in go1.23.1 darwin/arm64.
Is that this safe to make use of?
Fascinating instance certainly as I’m studying too.
package deal fundamental
import (
"fmt"
)
func fundamental() {
depend:=5
for vary depend{
fmt.Println("depend", depend)
}
}
Outputs:
depend 5
depend 5
depend 5
depend 5
depend 5
Beneath instance is like in Python, can be price so as to add your one to official GO “A Tour by GO” and to GO by instance web site with clarification.
for i := vary 3 {
fmt.Println("vary", i)
}
it can print:
vary 0
vary 1
vary 2
Python code equal
for i in vary (3):
print("vary", i)
vary 0
vary 1
vary 2