Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

71%
+3 −0
Q&A Understanding "logical OR" and "logical AND" in programming languages

One thing I'd like to add to Lundin and r.zwitserloot‭ answers, which is something that I think is rather important: The "or" in programming is inclusive. The "or" in most languages (all those I k...

posted 20d ago by Alexis Wilke‭

Answer
#1: Initial revision by user avatar Alexis Wilke‭ · 2024-11-28T05:45:55Z (20 days ago)
One thing I'd like to add to Lundin and r.zwitserloot‭ answers, which is something that I think is rather important:

The "or" in programming is inclusive. The "or" in most languages (all those I know of: "or", "ou", "ó", "order"...) is exclusive.

If we look at the truth tables of the AND, OR, and XOR we have:

    A B  AND  OR  XOR
    -----------------
    0 0   0   0   0
    1 0   0   1   1
    0 1   0   1   1
    1 1   1   1   0
          ^       ^
          |       |
          |       +--- language OR
          |
          +--- language AND

As we can see, in a programming language "if A or B ..." means that A can be true, B can be true, or A and B can be true. In our languages, if A and B are both true, we often don't use the work "or".

> _Do you want the blue or the red pill?_

On top of that, in most programming languages, you do not have a logical XOR operator. You often have a bitwise XOR, though. Usually using `^` character, at least in C and derivatives.

One way I've seen people deal with the inclusive "or" in English is by using the "and/or" double conjunction: A and/or B ...