Conditionals a vital to coding because they are essential parts of building blocks. They are the structure that decides when and if a code will be executed. Conditionals are functions to be executed if other functions cannot be (true or false).
If I designed a thermostat program, it would populate users’ mobile devices with messages indicating the current temperature followed by a message that goes accordingly. For example;
Let freezing =
Let cold = <50
Let gettingHot = >50
Let hot = <= 75
Let burning = <=101
Func whatsTheWeatherLike (_ number: Int)
If gettingHot {
Print( “It’s starting to get hot, no need to alarm yet but start looking for a pool”
} else if hot {
Print(“ Did you find that pool yet?”)
} else if burning {
Print ( “Alright! We’re cooking now!!”)
} else if cold {
“Whoa! Did you feel that bone shake or was it just me? Time to bundle up unless you’re Wim Hof.”
} else freezing {
Print (“Is Ice Age the 15th filming in town?”)
}
Granted, this code doesn’t work and there’s probably a simpler way of doing it. I’m currently learning Swift and look forward to seeing some suggestions to learn from.
Top comments (0)