This is just a basic programming question regarding conditional if
. Let say I have something like this:
if(a == 1 || a == 2 || a == 3)
{
var $myvar = 10;
// do stuff if the value of a is either 1, 2 or 3
}
if(a == 1)
{
var total = $myvar + 1;
// do stuff if the value of a is 1
}
if(a == 2 || a == 3)
{
var total = $myvar + 1;
// do stuff if the value of a is either 2 or 3
}
It's pretty clear what I'm trying to do in the code above. As you can see, we have some common conditions in here (for example, a == 1
is common in 2 of the 3 conditions). Also, please notice that I have a variable $myvar
that I want to be declared ONLY if a == 1 || a == 2 || a == 3
and access it in my other two conditions. Can anybody think of another (possibly cleaner) way of doing this?