Reputation: 53
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 validate3
to be checked too.
Upvotes: 0
Views: 90
Reputation: 13059
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.
Upvotes: 2