#Code is not entering for loop.

9 messages · Page 1 of 1 (latest)

cedar python
#

Hey there my code does not seem to enter the for loop (with the i:=0;i>3;i++). I have no idea why. Cant seem to figure out why it just skips over it.

func main() {
    file, err := os.Open("input.txt")
    if err != nil {
        fmt.Println("Error, reading file")
        fmt.Println(err)
    }
    defer file.Close()
    scanner := bufio.NewScanner(file)
    const maxCapacity int = 200000
    buf := make([]byte, maxCapacity)
    scanner.Buffer(buf, maxCapacity)
    var group1 int
    fmt.Println("before the loop")
    for i := 0; i > 3; i++ {
                fmt.Println("Inside the for loop")
        for scanner.Scan() {

            fmt.Println("Were inside the 2nd for loop")
            x, err := strconv.Atoi(scanner.Text())
            fmt.Println(x)
            if err != nil {
                fmt.Println("Error converting number inside the 3Adding loop")
            }
            group1 += x
        }
        fmt.Println("Inside for loop but at end")
    }
}
#

Not sure if I'm not seeing something obvious but ye. The output of this is just " Before the loop" nothing else printed.

flint slate
#

i:= 0; i > 3

#

If i is zero, it's not greater than three.

cedar python
#

oh...

#

I see.

#

THank you ❤️ I was being stupid Q_Q as always

#

!solved