spool-lang / Spool-Legacy-Repo

Legacy repo for the Spool programming language.
3 stars 0 forks source link

Conditionals #6

Open RedstoneParadox opened 5 years ago

RedstoneParadox commented 5 years ago

Basics

Conditionals are used to test conditions using conditional operators such as == and != and evaluate to either true or false.


#Returns true
(1 == 1)

#Returns false
(1 == 2)

== Tests if two objects are equal. != Tests if two objects are not equal. > Greater than < Less than >= Greater than or equal to. <= Less than or equal to. within (Keyword) Within the specified range.

Chaining

Conditional statements can be chained together using the keyword and to test if both are true and or to test if one or the other is true.


#returns true
(1==1) and (2==2)

#returns false
(1==1) and (2==1)

#Returns true
(1==1) or (2==1)

#returns true
(1==1) and (2==2) or (1==2)

When chaining conditionals, they are evaluated from left to right; you can wrap chained conditionals in parenthesis to achieve the desired Order of Operations.


#Returns true if either the first two are true or the third one is true.
( 1==1) and (2==2) or (1==2)

#Returns true if either the second or third one is true and if the first one is true.
(1==1) and ((2==2) or (1==2))