locked
Count If Conditions in program RRS feed

  • Question

  • Hi.

    I have a very simple question , i need to count if conditions written in my program , e.g  i load cs file and my program should validate my code and return me total sum of if conditions used...

    help me


    Ali Muhammad

    Friday, February 12, 2016 12:30 PM

Answers

  • Muhammed,

    Answer is very simple and straight.

    1. Declare a local variable int ifConditionCount=0;

    2. Increment ifConditionCount = ifConditionCount + 1; before to each if().

    This is how it works.

    Thanks, Please mark this answer if this is helpful.

    Friday, February 12, 2016 1:19 PM
  • Ali Muhammad,

    Shafiq is almost there but you need to remember a few things:

    • If you have multiple classes in a namespace you need a global variable.
    • You say you want to only count the Ifs when they are used so make sure you increment your counter inside your If condition. Incrementing it outside the If will count all Ifs, used or not.
    • As well, using Shafiq's example, it is easier to increment using ifConditionCount++.

    Let us know if this helps.

    Friday, February 12, 2016 7:19 PM

All replies

  • Muhammed,

    Answer is very simple and straight.

    1. Declare a local variable int ifConditionCount=0;

    2. Increment ifConditionCount = ifConditionCount + 1; before to each if().

    This is how it works.

    Thanks, Please mark this answer if this is helpful.

    Friday, February 12, 2016 1:19 PM
  • Ali Muhammad,

    Shafiq is almost there but you need to remember a few things:

    • If you have multiple classes in a namespace you need a global variable.
    • You say you want to only count the Ifs when they are used so make sure you increment your counter inside your If condition. Incrementing it outside the If will count all Ifs, used or not.
    • As well, using Shafiq's example, it is easier to increment using ifConditionCount++.

    Let us know if this helps.

    Friday, February 12, 2016 7:19 PM