jeudi 5 mars 2020

More Efficient If/Else Statement in C

I was wondering if the two different codes below performed better than the other. They do the same function. I would think that when implementing this code you would want the if statement to contain the argument that would occur more frequently.

Option #1

if(hoursWorked <= 40){
    workedOvertime = 0;
}
else{
    workedOvertime = 1;
}

Option #2

if(hoursWorked > 40){
    workedOvertime = 1;
}
else{
    workedOvertime = 0;
}

Aucun commentaire:

Enregistrer un commentaire