You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Help/expressions.md
+47-2Lines changed: 47 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,18 @@ Operators are used in conjunction with individual values to perform calculations
14
14
5+3*4
15
15
```
16
16
17
-
ShapeScript supports common [infix](https://en.wikipedia.org/wiki/Infix_notation) math operators such as +, -, * and /. Unary + and - are also supported:
17
+
ShapeScript supports all the standard [infix](https://en.wikipedia.org/wiki/Infix_notation) arithmetic operators:
‐ | minus | Subtracts the right value from the left value
23
+
* | times | Multiplies the left value by the right value
24
+
/ | divide | Divides the left value by the right value
25
+
26
+
<br>
27
+
28
+
Unary + and - are also supported:
18
29
19
30
```swift
20
31
-5*+7
@@ -41,6 +52,40 @@ Whereas this expression would be interpreted as a 2D vector of 5 and -1:
41
52
5-1
42
53
```
43
54
55
+
## Equality and Comparison
56
+
57
+
In addition to the standard arithmetic operators, ShapeScript also has equality and comparison operators, which can be used in [conditional logic](control-flow.md#if-else). The following infix comparison operators are supported:
= | equal | Compares two values and returns `true` if they are equal
62
+
<> | not equal | Compares two values and returns `false` if they are equal
63
+
< | less than | Returns `true` if the left value is less than the value on the right
64
+
<= | less than or equal | Returns `true` if the left value is less than or equal to the right
65
+
> | greater than | Returns `true` if the left value is greater than the value on the right
66
+
>= | greater than or equal | Returns `true` if the left value is greater than or equal to the right
67
+
68
+
<br>
69
+
70
+
**Note:** You may have used other languages where `=` is written as `==`. This is generally because in such languages the `=` operator is used for assignment, and re-using the same symbol would cause ambiguity. This is not a problem in ShapeScript.
71
+
72
+
While these operators are typically used with numeric inputs, the *output* is a boolean value (`true` or `false`). These values are most commonly used in conjunction with with the `if/else` control flow statement. For example:
73
+
74
+
```swift
75
+
if rnd >0.5 {
76
+
print "heads"
77
+
} else {
78
+
print "tails"
79
+
}
80
+
```
81
+
82
+
But they can also be assigned to a symbol and passed around:
0 commit comments