jeudi 22 novembre 2018

How to do double 'if' statement that jumps to the same 'else' if any is false

The title might be confusing, I'm really not sure how to name my problem more properly.

Basically what I'm trying to achieve is: If 'first' is false I want to go to 'else' always but if WE ARE checking for 'second' I want to go to 'else' if 'first' OR 'second' is false. Just look at the code:

    //'first' and 'second' might be true, might be false

    if(first)
    {
        if(checkSecond && !second)
        {
            //If we allow checking for 'second' and 'second' is false go to else (but we can't)
        }

        if(!checkSecond)
        {
            //Do something when 'first' was true and we are not checking 'second'
            checkSecond = true; //allow checking second;
        }
    }
    else
    {
        //Reset when 'first' is false
        //or
        //when 'second' is false if we allow checking it (but we can't)
        checkSecond = false; //don't allow checking second;
    }

I figured out some syntax how it could look like if I were to implement it, it might make my problem a bit cleaner (or maybe there already exists something like that that I don't know)

    if (first && if (checkSecond) second) //go to else if 'first' is false OR 'second' is false if 'checkSecond' is true
    {
        if(!checkSecond)
        {
            //Do something when 'first' was true and we are not checking 'second'
            checkSecond = true; //allow checking second;
        }
    }
    else
    {
        //Reset when 'first' is false
        //or
        //when 'second' is false if we allow checking it
        checkSecond = false; //don't allow checking second
    }

Aucun commentaire:

Enregistrer un commentaire