-3

Python programmer here.

I don't know how to write this. I tried using 'if !in' and '!if in', but I don't know how. Tried to Google it but got no results.

MountainSlayer
  • 291
  • 1
  • 5
  • 14

2 Answers2

2

The correct syntax is

if(!condition){
    expression();
}

Note that you need parenthesis around the condition.


@plalx wants a formal definition, and here you go:

IfStatement:
    if(Expression) Statement else Statement
    if(Expression) Statement

In case of any ambiguity the else would be matched with the nearest if.

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
  • 1
    Why not expressing your comment in the code rather than making it a comment? `if (!(condition)) { ... }` Commenting rather than making code explicit is a very bad habit most programmers have... ;) – plalx Nov 08 '16 at 18:30
  • 1
    @plalx I believe this is the cleanest way to demonstrate the syntax. – Derek 朕會功夫 Nov 08 '16 at 18:31
  • How could it be the cleanest if you need an additional comment? This sounds like, to perform some process you need to: `doThis() //by the way you also need to doThat() before calling doThis()`. It's much cleaner to just `doThat(); doThis();` – plalx Nov 08 '16 at 18:33
0

If you have some value:

var excludeMe = "something unwanted";

Then you can use the following if statement:

if(myTestCase !== excludeMe) { //do something...} 

Keep in mind that != does not check type and !== does check type. So, 1 != "1" is false and 1 !== "1" is true.

Jon Diamond
  • 200
  • 1
  • 2
  • 11