前往:如何更改for循环迭代器类型?

Go uses int for the iterator by default from what I can tell, except I want uint64. I cannot figure out a way to change the type of for loop iterator in Go. Is there a way to do it inline with the for statement? The default type of int causes problems when I try to do something in the loop, like a mod operation (%).

func main() {                                                                                                                               
    var val uint64 = 1234567890                                                 
    for i:=1; i<val; i+=2 {  
        if val%i==0 {
        }                                        
    }                                                                          
} 

./q.go:7: invalid operation: i < val (mismatched types int and uint64)
./q.go:8: invalid operation: val % i (mismatched types uint64 and int)

You mean something like this?

for i, val := uint64(1), uint64(1234567890); i<val; i+=2 {
    // your modulus operation
} 

http://play.golang.org/p/yAdiJu4pNC