Flow control is one of the most important parts of programming. It allows programs to perform operations that are not defined to give the same output each time and to vary based on input. This type of flow control is called a decision.
Simply put, a decision is like a road with many roads branching off of it - go left and you end up in town A or go right and you end up in town B. In this situation, a decision is made. The decision is based on some condition; you are going there because there is something you need there and it has it. This is where conditions come in.
What is a condition?
A condition is a set of requirements that must be satisfied. A condition evaluates to a Boolean value, true or false. Conditions can be used in control flow statements such as if statements and loops so they are a major part of any computer program. Alternatively, conditions can be evaluated and stored in a variable.
The next example shows conditions in YASS syntax.
$result1 = true or false $result2 = true and false $result3 = true and true $result4 = false or false
Conditions can be used not just to check for equality, but also to access mathematical comparisons:
$result1 = 1 > 5 $result2 = 1 < 5 $result3 = 7 >= 7 $result4 = 6 <= 7 $result5 = $x == $y
Ternary operations
Further to your standard inline conditional evaluation, with many languages, YASS included (from version 1.4.3), there is an option that allows you to perform inline ternary operations.
In computer science, a ternary operation is one that takes in three arguments and provides one output.
Ternary operations allow you to write a very short statement that returns a single output that does not have to be limited to true or false.
Take a look at this example:
$x = 15 $y = 20 $z = $x > $y ? "Yes" : "No" print($z)
Match statements
ZPE 1.9.1 introduced the match
statement. The match
is an inline conditional expression that evaluates directly. It can be assigned to a variable or it can act like
a when-is statement.
$x = 15 $y = 20 $z = $x > $y $result = match($z : true => "Yes" false => "No" ) print($result)