Go don't call function. This is a go bug or not?

Hi

My code

package main

import (
	"fmt"
)

func main() {

	c := false
	c = c || doWork(1)
	c = c || doWork(2)
	c = c || doWork(3)
	
	fmt.Print(c)
}

func doWork(a int) bool {
	fmt.Printf("doWork %v\n", a)
	return true
}

Result

doWork 1
true

I expect to see

doWork 1
doWork 2
doWork 3
true

Please tell me what is wrong?

1 Like

In first_condition || second_condition , if the first condition is true, the second condition will not be called.

4 Likes

Thank you

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.