0

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.

2
  • 1
    Based on your previous questions, you already know that parentheses are required. Are you actually trying to write a "if not in (array)" condition? Commented Nov 8, 2016 at 18:29
  • 1
    Yes that is what I am trying to do Commented Nov 8, 2016 at 18:32

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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 I believe this is the cleanest way to demonstrate the syntax.
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();
1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.