This is a general programming question. I have multiple flags that get set in code with a 1 or 0. Depending on the combination of flags set I decide what path my code needs to follow. I've been using singular if statements to process them, but I keep thinking there is a better way to do this.
I would like to reduce the amount of if statements I need and streamline the code. I'll give an example below and I would love some suggestions.
flag1 = 1
flag2 = 0
flag3 = 0
...
flag8 = 0
flag9 = 1
flag10 = 0
if(flag1 = 0 and flag2 = 0 and ... flag10=0)
// do something
else
//don't do something
end if
if(flag1 = 1 and flag2 = 0 and ... flag10=0)
// do something
else
//don't do something
end if
if(flag1 = 0 and flag2 = 1 and ... flag10=0)
// do something
else
//don't do something
end if
I wind up with a whole lot of if statements. This problem is language agnostic. I'm writing in VBScript (don't laugh, I have to for this implementation) but it could be in C#, Javascript, whatever.
Aucun commentaire:
Enregistrer un commentaire