Share Your Experience: Take the 2024 Developer Survey

# Tag Info

Accepted

### && 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 ...
• 46.2k

### Is there a keyword or operator for "nor"?

Although mainstream languages do not have dedicated NOR and NAND operators, some lesser-known languages (for example, some "golfing" languages) do. For example, APL has ⍱ and ⍲ for NOR and NAND, ...
• 1,652

### Is there a keyword or operator for "nor"?

No, there is no nor operator in any high level mainstream programming language. Why ? Mainly because it is difficult to read: it requires the mental combination of several operators ( "and not", ...
• 78k

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

In C# these are all logical operators. int x = 0xABCD & 0xFF // x == 0xCD && and || are called "conditional logical operators" because they are short-circuiting. bool ...
• 200k

### Is there a keyword or operator for "nor"?

@KilianFoth's comment on the question is spot on. You can synthesize nor from not and or: if (x nor y) is exactly the same as if (not (x or y)) Introducing nor as a separate operator would ...
• 2,355
Accepted

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

The != operator is more commonly used nowadays because of the overwhelming influence in C. But how did C get there? The mathematical operator for inequality is ≠. Some languages do use this operator ...
• 134k
Accepted

### Any reason to not use a triple not?

You can triple a not operator, but that doesn't really buy you anything except code obfuscation. The single not operator (!) converts its operand to a boolean and yields the inverse boolean value. By ...

### Is there a keyword or operator for "nor"?

Yes, APL and some of its dialects have nor (and nand). In APL, nor is denoted ⍱ (since ∨ is or and ~ is not): ∇ result←ExampleOne color :If (color≡'green')⍱(color≡'blue') result←'warm' :...
• 274

### Any reason to not use a triple not?

I'm not going to not tell you not to do this. I'm not sure this is not a not good idea or not. It might not be not confusing (not). It's not true that something is not not not true. In short, do ...
• 27.5k
Accepted

### Conditional vs Logical Testing

If a Then If b Then If c Then If d Then If e Then x = "Passed" Else x = "Failed" That is some horrendous code right there, and it doesn't do what you think it does either: the 3 "methods" you're ...
• 1,720

### Is there a keyword or operator for "nor"?

This answer is from the assembler language for a computer made in the mid 1960s. That's pretty obscure, but in some respects it addresses your question. DEC (Digital Equipment Corporation) launched ...
• 806

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

add more functions: buttonPress() { if(input) { process(a, b) } else { process(b, a) } } process(a, b) { for(i=0 ... }
• 76.4k
Accepted

### Is it bad practice to use nullptr in ternary operation?

This is not a good idea because the ternary operator is intend to be used as an expression, and the recommended C++ core guideline is to avoid complicated expressions. Here you only use only the ...
• 78k

### Is it bad practice to use nullptr in ternary operation?

In C++23 the code will not compile, as constructing a std::string from nullptr is explicitly disabled. Before that, constructing a std::string from a null pointer (of type const CharT*) caused ...
• 9,051
Accepted

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

You can use a ternary operator: if (input ? a < b : a > b) { ... }. However, without properly naming the conditions or adding a comment your code will be harder to read, as it might not be ...
• 16.6k

### Why don't languages like C have NAND operators?

I have seen only a few languages that implemented a NAND keyword. Remember that source-code is designed to be expressive of the logic that is needed to solve the problem at hand. It is entirely up to ...
• 1,793

### Conditional vs Logical Testing

I feel I must insist on readable, flexible, debugable code. If a = False Then Return "Failed" If b = False Then Return "Failed" If c = False Then Return "Failed" If d = False Then Return "Failed" ...
• 110k
Accepted

### Why don't languages like C have NAND operators?

There are so many levels in between the source code of some program and the circuits on a chip. While some microarchitecture details definitely have a high-level performance impact, the ability to ...
• 134k

### Why don't languages like C have NAND operators?

NAND doesn’t match the mental image of logic that normal people including software developers have. A nand B doesn’t make sense to a normal person. It’s absolutely fine in an instruction set, but not ...
• 45.7k

### Is it bad practice to use nullptr in ternary operation?

Illegal? no. But it can provoke undefined behavior. You're just looking for a default value when menuSelect is some unanticipated value. Any good reason operation can't be "undefined"? When ...
• 110k

### Is it bad practice to use nullptr in ternary operation?

Is this bad practice? Yes, it is terribly unreadable. Unless your code is actually performance sensitive and you have profiled it, found this code path is the hot path, and shown this construct is ...
• 24.3k

### Is there a keyword or operator for "nor"?

The nor operator as you described it would not be repeatable, which is bound to lead to lots of difficult to spot bugs. Your "Example 2" is essentially this: if (false nor false) { becomes if (true) ...
• 303

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

The C Language: #include <stdio.h> int main() { printf(2||3 ? "true\n" : "false\n"); return 0; } In C, zero is interpreted to be false. Any other value is interpreted to be true. ...
• 200k

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

The different representations of the inequality operator is largely the result of historical reasons. The very earliest languages were developed in relative isolation compared to what we see today ...

### Is there a keyword or operator for "nor"?

Perl has the unless keyword that lets you invert conditionals: unless (\$color eq 'green' or \$color eq 'blue') { # code } While not NOR operator, you can express your intent in a similar way.
• 1,747

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

Well... I think that a good way to do that is to encapsulate your code into procedures/functions and correctly naming your steps/conditionals, like this: function iterateOverSomething() { for (...) {...
• 131

### Why don't languages like C have NAND operators?

There is absolutely no reason to minimize the number of gates involved in executing an instruction. The amount of gates that are used to read the instruction from memory, figuring out what it does, ...
1 vote

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

In a language where you have lambdas you can easily return predicates (functions return booleans) to eliminate nested if. predicate = if (input) { (a, b) => a < b } else { (a, b) => a >...
• 200
1 vote

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

You can always reduce cyclomatic complexity this way: for(i = 0; i < length; i++) { flag = input; if ((flag && (a < b)) || (!flag && (a > b))) { ...
• 39.4k
1 vote

### Conditional vs Logical Testing

You can do in following way also. if(!A) then return "Failed"; else if(!B) then return "Failed"; This could increase overall performance.
• 339

Only top scored, non community-wiki answers of a minimum length are eligible