Is there a neither A nor B
syntax?
Oh ... you wanted the "ain't" keyword?
VB adds Ain't Keyword
(Newswire 8-19-2004)
Microsoft has announced that Visual Basic will add the "Ain't" keyword to the language. According to a source on the VB.NET team "With VB, we want the language to work the way you think. Extensive usability studies have demonstrated to us the benifit of adding Ain't to the language."
Addition of the keyword would allow such syntax as
If ThisThing Ain't Nothing ThenAccording the source "We're just trying to keep up with advances in the English language which, as you know, is changing almost as fast as technology itself." The VB team believes that ain't is poised to finally be a fully supported keyword in the English language, and they feel that if they don't include the keyword in this release, they may fall well behind English before their next chance to update VB. However, hotly debated is what "Ain't" should equate to. In it's most popular form, the above line of code would translate to:
If ThisThing Is Nothing ThenHowever, everyone's 2nd grade english teacher has made it clear that "Ain't Nothing" actually means "Is Something", as it's a double-negative. Meaning the correct equivelant would be
If ThisThing IsNot Nothing ThenMicrosoft is in no hurry to rush through this decision, state sources, "Look, between VB.NET Beta 1 and Beta 2, we had to change the definition of 'true'. We don't want to go through that again."
However language purists declare that this whole approach is misguided, noting that "Ain't" is a contraction for "am not", and saying "If ThisThing Am Not Nothing" is just poor grammar. Better alternatives, they say, would include resurecting i'n't, as in "If ThisThing I'n't Nothing". But even this may not be far enough states linguist Jacque Leblanc, "I insist that the perpetuation of the double negative is the root cause of this issue, but as of yet, no one is really willing to discuss the obvious elephant in the room. The true solution would be to allow 'If ThisItem Is Something Then.'"
Microsoft is also reported to be experimenting with "AsIf", "Maybe", and "Totally". In addition, "Catch" will likely be replaced with "Doh!", and "Finally" will be replaced with "Whatever".
source: http://web.archive.org/web/20050308014055/http://ea.3leaf.com/2004/08/vb_adds_aint_ke.html
While there isn't a built-in syntax to do this, I'd suggest you take a look at the list of supported logical operators and then carefully study De Morgan's laws. Sufficient knowledge in these two fields will allow you to write any logical statement in if–else if syntax.
EDIT: To completely answer your question (although this has been done already in other answers), you could write a neither–nor statement like this:
if (!A && !B) { DoStuff(); }
To encode "if neither A nor B":
if (!A && !B) { ... } //if (not A) and (not B)
or:
if (!(A || B)) { ... } //if not (A or B)
Here you go:
class neither_t
{
bool lhv;
neither_t(bool lhv): lhv(lhv) {}
public:
bool nor(bool rhv) const
{
return !lhv && !rhv;
}
friend neither_t neither(bool lhv);
};
neither_t neither(bool lhv)
{
return neither_t(lhv);
}
#include <cstdio>
int main()
{
int x = 3;
if (neither(x == 1).nor(x == 2)) {
puts("OK");
}
}
No, there isn't.
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