jeudi 21 mars 2019

More efficient way of using lots of if else statements (swift playground)

I'm trying to do this in swift playground and I was wondering if there was a more efficient way:

if(doesSmoke){
    yearsTotal = yearsTotal - 7.5
}
if hoursSleepAvg < 7 {
    yearsTotal = yearsTotal - yearsTotal / 100.0
}
if hoursSleepAvg > 8 {
    yearsTotal = yearsTotal - yearsTotal / 100.0

There are a lot more if statements. Does anyone have a solution?

Aucun commentaire:

Enregistrer un commentaire