vendredi 5 mai 2017

Should if statements be avoided when you want to set X to certain value but you check its value first

If my X is a boolean. And when I need to set X to true only when X is false and vise versa. Is it better to check first if X is false before setting it to true?

if(!x)
{
    x = true;
}

or I'll just set it directly to true.

x = true;

What I am concerned about is which one will take up more work? Although this seems to be something that can be ignored.

Aucun commentaire:

Enregistrer un commentaire