Skip to content

Commit 66e6d7b

Browse files
committed
Add explanation of if...else statement
1 parent c681720 commit 66e6d7b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,46 @@ int add(int a, int b) {
8484
(get_local $b)))
8585
```
8686

87+
### if...else statement
88+
89+
There are two ways to express `if`...`else` statement
90+
91+
```WebAssembly
92+
(get_local $condition)
93+
(if
94+
(then
95+
;; statement(s)
96+
)
97+
(else
98+
;; statement(s)
99+
)
100+
)
101+
```
102+
103+
```WebAssembly
104+
(if
105+
(get_local $condition)
106+
(then
107+
;; statement(s)
108+
)
109+
(else
110+
;; statement(s)
111+
)
112+
)
113+
```
114+
115+
`if` can also return a result
116+
117+
```WebAssembly
118+
(if (result i32)
119+
(get_local $condition)
120+
(then
121+
i32.const 4)
122+
(else
123+
i32.const 5)
124+
)
125+
```
126+
87127
### Operators
88128
| | i32 | i64 | f32 | f64 |
89129
|:-:| --- | --- | --- | --- |

0 commit comments

Comments
 (0)