Boolean operations

Trying to pick up on a boolean value, but the compiler doesn’t seem to like or-equal.

Is there a good reason for this? Or am I just not holding my mouth right?

1 Like

flag = flag || condition (untested)

Or said another way,

if !flag {
flag = condition

prog.go:14: invalid operation: flag |= place[r + i][c] (operator | not defined on bool)

is quite simple, constructions like a |= b works but not for bool type.

Okay, this is annoying. + can be used to concatenate strings, but the simple or operator can’t used on booleans. You have to use the special boolean or (||) operator. Is there a good reason for this? I’m sure there probably is, but I can’t imagine what it might be.

The bitwise operators are part of the set of arithmetic operators and defined for integer types. The logical operators are somewhat fewer and defined for booleans. Certainly some of the bitwise operators could have worked on the booleans, but since most of the arithmetics don’t make sense for booleans it would be an odd special case. And conceptually, mathematically, a boolean is a truth value and not a one or zero bit, although it can sometimes be represented that way in computers.

1 Like

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