user3244
user3244

Reputation: 35

Code inside nested If statements

is there be any performance effect on "Lines of code" running inside nested ifs?

if (condition_1)
{
   if (condition_2)
   {
      if (condition_n)
      {
          /* Lines of code */
      }
   }
}

Upvotes: 0

Views: 298

Answers (1)

Mark Byers
Mark Byers

Reputation: 838086

No, there shouldn't be a performance effect. Any decent compiler should easily be able to cope with that and optimize it correctly. The biggest problem with your code is not the performance but the readability.

By the way, you could easily rewrite it to the following more readable code:

if (condition_1 &&
    condition_2 &&
    ...etc...)
{
     /* Lines of code */
}

Upvotes: 4

Related Questions