Adding Logic

Conditional statements allow you to add a level of logic to your scripts. Using if and switch statements we can create reactions for when one or more conditions are met.

If

If statements are probably the most popular ways to add logic to a project. They allow you to set reasoning based on, if this, do this, else do this

if myNumber < 10 then
 put "That is to low"
else if myNumber > 10 then
 put "That is to high"
else
 put "That is correct"
end if

Switch

The swtich statement is executed line byline, starting from the top. If you do not include a break statement, it will continue evaluating each condition.

put "wet" into myWeather
 switch myWeather
 case warm
 put "Wear a short shirt, its warm outside"
 break
 case wet
 put "take your umbrella, its raining"
 break
 default
 put "I don't know what you shoud wear"
 end switch

// the above switch statment will output: take your umbrella, its raining

Leave a Reply