DEV Community

keepoSteepo
keepoSteepo

Posted on

1 1

Why Conditionals?/ My attempt at a thermostat program

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.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs