Skip to content

Commit 516c0e8

Browse files
Merge pull request #127 from vlobzakov/vlobzakov-single-line-if-statement
Update conditions-and-iterations.md
2 parents a3e41d4 + 6ceac26 commit 516c0e8

File tree

1 file changed

+98
-1
lines changed

1 file changed

+98
-1
lines changed

docs/creating-manifest/conditions-and-iterations.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
11
# Control Flows: Conditions and Iterations
22

3+
**Comparison** and **Logical** operators are used in *conditional* statements and serve to test for `ture` or `false`.
4+
5+
## Comparison Operators
6+
7+
The Comparison operators are used in logical statements to determine equality or difference between variables or values.
8+
9+
Let's assume that `x = 5`. The table below explains the comparison operators:
10+
11+
| Operator | Description | Comparing | Returns |
12+
|--------------------|-------------------------------------|-----------|----------|
13+
| == | equal to | x == 8 | false |
14+
| == | equal to | x == 5 | true |
15+
| == | equal to | x == "5" | true |
16+
| | | | |
17+
| === | equal value and equal type | x === 5 | true |
18+
| === | equal value and equal type | x === "5" | false |
19+
| | | | |
20+
| != | not equal | x != 8 | true |
21+
| | | | |
22+
| !== | not equal value or not equal type | x !== 5 | false |
23+
| !== | not equal value or not equal type | x !== "5" | true |
24+
| !== | not equal value or not equal type | x !== 8 | true |
25+
| | | | |
26+
| > | grater than | x > 8 | false |
27+
| < | less than | x < 8 | true |
28+
| >= | grater than or equal to | x >= 8 | false |
29+
| <= | less than or equal to | x <= 8 | true |
30+
31+
## Logical Operators
32+
33+
The logical operators are used to determine the logic between variables or values. Let's take that `x = 6` and `y = 3`. The table below explains the logical operators:
34+
35+
| Operator | Description | Example |
36+
|--------------------|-------------------------------------|------------------------------|
37+
| && | and | (x < 10 && y > 1) is true |
38+
| == | or | (x == 5 || y == 5) is false |
39+
| == | not | !(x == y) is true |
40+
41+
42+
43+
44+
345
## Conditions
446

547
The main conditional statement is <b>*if*</b>. Within this parameter, all the available <a href="../placeholders/" target="_blank">placeholders</a> and their objective JavaScript mappings can be used.
@@ -204,7 +246,7 @@ onInstall:
204246
```
205247
@@!
206248

207-
### **Else**
249+
### Else
208250

209251
In case the conditional statement should be complemented by the opposite comparison and respective action the ***else*** conditional operator can be accommodated.
210252

@@ -431,6 +473,61 @@ onInstall:
431473
```
432474
@@!
433475

476+
### Single line *if* statement
477+
478+
Another ***if-else*** combination can be represented as a single ***if*** statement when multiple conditions are required to be checked and the statements nesting is not mandatory.
479+
It is applicable if any condition or all of the conditions in the statement may lead to the same outcome.
480+
For example:
481+
482+
@@@
483+
```yaml
484+
type: install
485+
name: '[CS:Conditions] - action single line "if"'
486+
487+
globals:
488+
a: 1
489+
b: 2
490+
491+
onInstall:
492+
- log: "-- single line if test --"
493+
- if ((globals.b == 2) && (globals.a == 1) && (globals.a == 1)):
494+
assert: true
495+
496+
- log: "-- another single line if test --"
497+
- if (globals.a == 2 || globals.a == 3 || globals.a == 1):
498+
assert: true
499+
```
500+
```json
501+
{
502+
"type": "install",
503+
"name": "[CS:Conditions] - action single line \"if\"",
504+
"globals": {
505+
"a": 1,
506+
"b": 2
507+
},
508+
"onInstall": [
509+
{
510+
"log": "-- single line if test --"
511+
},
512+
{
513+
"if ((globals.b == 2) && (globals.a == 1) && (globals.a == 1))": {
514+
"assert": true
515+
}
516+
},
517+
{
518+
"log": "-- another single line if test --"
519+
},
520+
{
521+
"if (globals.a == 2 || globals.a == 3 || globals.a == 1)": {
522+
"assert": true
523+
}
524+
}
525+
]
526+
}
527+
```
528+
@@!
529+
530+
434531
## Iterations
435532

436533
### ForEach

0 commit comments

Comments
 (0)