Questions tagged [logical-operator]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4 votes
5 answers
419 views

Is it bad practice to use nullptr in ternary operation?

I've set up a ternary operator in place of a pile of if-else's, the final expression being nullptr in order to finish the loop, like so: int menuSelect; std::string operation=""; (...
Hench's user avatar
  • 51
3 votes
5 answers
716 views

What is the best way to make an if statement condition itself conditional?

Apologies if this is answered elsewhere here but this specific question is somewhat hard to search for as you might see. I'm writing a script currently that essentially has a simple if-then within a ...
Rushkie's user avatar
  • 49
5 votes
5 answers
5k views

Why don't languages like C have NAND operators?

I know that some languages like APL have a dedicated NAND operator, but I'm thinking about languages like C, C++, Java, Rust, Go, Swift, Kotlin, even instruction sets, etc. since these are the ...
Ky -'s user avatar
  • 535
2 votes
3 answers
1k views

Any reason to not use a triple not?

If logical not ! will switch a boolean value from false to true or true to false and a double not !! will cast a value from one primitive type to boolean is there any reason one can not use a logical ...
1.21 gigawatts's user avatar
2 votes
4 answers
470 views

Conditional vs Logical Testing

I would like to get your code thought and views on using conditional vs logical testing. For example: To test the conditions of truthness of all of the following variables, their currect status is ...
Mohsen Alyafei's user avatar
58 votes
8 answers
18k views

Is there a keyword or operator for "nor"?

Is there an operator equivalent of nor? For example, my favorite color is neither green nor blue. And the code would be equivalent to: // example one if (color!="green" && color!="blue") { ...
1.21 gigawatts's user avatar
62 votes
3 answers
11k views

&& and || are not logical but conditional operators?

I am a bit confused by the MSDN C# documentation which states that & and | are logical operators and that && and || are conditional operators. I keep calling &&, || and ! logical ...
John V's user avatar
  • 4,918
6 votes
4 answers
963 views

Why is there both logical operators <> and !=?

The are two operators '<>' and '!=' used in programming languages with the same general meaning. '<>' can be used in PHP, SQL, and Pascal. '!=' seems to be more commonly used. What is the ...
Liam's user avatar
  • 171
-3 votes
3 answers
177 views

Was there some language(s) in which its logical operators returning a true or false only?

I remember in the past, for some languages which I can't remember, be it Fortran, Pascal, or Scheme, a logical operator 2 || 3 will always return a boolean value. But in the modern languages: ...
nonopolarity's user avatar
  • 1,827