I have an if statement in Go which looks like this:
if level & 1 {
// do something
} else {
// do something else
}
The level variable in my cause is of type uint. But when I do bitwise AND with 1, the result is not a boolean. This is a valid syntax for C, but apparently it doesn't work in Go. Any idea how to work around this?
If statements in Go must have type of bool, which you can achieve by using a comparison operator, the result of which is a bool:
if level&1 != 0 {
// do something
} else {
// do something else
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With