0

I'm writing an if statement that has multiple or in it. If validate1 returns true, it doesn't execute validate2 or validate3. But I need it to check validate2 and validate3.

I can't use && here, it is not satisfying my expectation as I tried. And I didn't want to write multiple if

Is there any way to solved this with one if statement?

if (this.validate1(x, y) || this.validate2(a, b) || this.validate3(c, d))
{ }
else {
  showError();
}

I tried with and situations. Every validation is returning an error, with and if one of them is passing the validation then it's going to next step. This is not what i want.

And i write something wrong validate2 or validate3to be checked too.

1
  • Write out a working version with nested if statements so we know exactly what you're trying to do. Commented Feb 28, 2018 at 14:22

1 Answer 1

2

How about

var val2 = this.validate2(a, b);
if (this.validate1(x, y) || val2 || this.validate3(c, d))
{ }
else {
  showError();
}

This way validate2 will always get called without changing the logic.

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

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.