G
Guest
I have some code that works fine, except for the fact that it has a lot of
embedded if statements. I don't think that this would be practice code, but I
wanted to tap into the knowledge of this group, and see what is the best way
to handle it. Basically, the if statements are used to check several
conditions of whether something is activated etc., and if it is, it outputs a
small piece of text and redirects the user to a new page. For each of the
conditions, there are 20 if statements. In the below, I am putting 1 piece,
but there are 20 IDENTICAL other lines to these, for each of the the ten
conditions. The first checks whether the condition is active, if the user is
an admin, and displays some text.
if (AdminUser())
{
if (_enableCondition1 == true)
{
output.Write(@"<img border=""0"" src=""foo""
align=""middle"">);
output.Write("<b>");
output.Write("foo" + "<br>");
}
else
{
output.Write("Foo Not Active" + "<br>");
}
}
.......
(then there are 20 more of these!)
then the other type is handled if it is found active:
if (_enableCondition1 == true)
{
if (foo1 == foo2)
{
fooMethod
}
}
Also 20 of these.
This seems to be inefficient to me. Is there a better way of handling it?
embedded if statements. I don't think that this would be practice code, but I
wanted to tap into the knowledge of this group, and see what is the best way
to handle it. Basically, the if statements are used to check several
conditions of whether something is activated etc., and if it is, it outputs a
small piece of text and redirects the user to a new page. For each of the
conditions, there are 20 if statements. In the below, I am putting 1 piece,
but there are 20 IDENTICAL other lines to these, for each of the the ten
conditions. The first checks whether the condition is active, if the user is
an admin, and displays some text.
if (AdminUser())
{
if (_enableCondition1 == true)
{
output.Write(@"<img border=""0"" src=""foo""
align=""middle"">);
output.Write("<b>");
output.Write("foo" + "<br>");
}
else
{
output.Write("Foo Not Active" + "<br>");
}
}
.......
(then there are 20 more of these!)
then the other type is handled if it is found active:
if (_enableCondition1 == true)
{
if (foo1 == foo2)
{
fooMethod
}
}
Also 20 of these.
This seems to be inefficient to me. Is there a better way of handling it?