i'm new in go, i want to know, how to write the output of loop for in txt file in golang here my code
package main
import (
"fmt"
"log"
"os"
)
func main() {
for i := 1; i <= 10; i++ {
if i%2 == 0 {
continue
}
fmt.Printf("%d ", i)
file, err := os.Create("result.txt")
if err != nil {
log.Fatal("Cannot create file", err)
}
defer file.Close()
fmt.Fprintf(file, " x equal to %d", i)
}
}
but i get 9 instead of 1 3 5 7 9 so how to fix that