jeudi 21 janvier 2016

a more efficient 'if' statement for multiple options

I wonder if anyone has some ideas to make the following shorter and more efficient. I have 3 dropdowns where a user selects lower age limit, upper age limit and gender. They can select as many as they want, even none. I then have an if statement that will do a process based on what they select. Assume l, u and g are the parameters that are passed.

if((age > l && age < u && gender == g)
|| (age > l && age < u && g == null)
|| (age > l && u == null && g == null)
|| (age < u && gender == g && l == null)
|| (age < u ...etc etc)

Is there a better way of forming this rather then a tedious if statement?

Aucun commentaire:

Enregistrer un commentaire