Condensing If Statements

Is it possible to condense If statements like the following:

if (action = "Run" or action = "Escape" or action = "Flee")

...into something like this?

if (action = "Run", "Escape", "Flee")

And if so, how?


The most efficient way would be using a switch block.

switch (action) {
  case ("Run", "Escape", "Flee") {
    // code here
  }
}

You can do a switch block with only one case; though in your example I suspect you will want one for each possible action.


You could alternatively do if (ListContains (Split("Run;Escape;Flee"), action)) { or if (Instr ("Run;Escape;Flee", action) > 0) {.

But if your code is going to continue with else if (action = ..., then you should definitely be writing a switch block with one case for each option.


Log in to post a reply.

Support

Forums