The content on this page is written in Chinese, and then traslated into English by machine. More accurate traslations are welcome at: https://github.com/wa-lang/man/tree/master/en
Ending's law: "Any application that can be compiled to WebAssembly, will be compiled to WebAssembly eventually."
4.4. if statements
The general form of conditional statements is:
if initial statement, conditional expression {
code block 1
} else {
Code block 2
}
Among them, conditional expression
must be of Boolean type. The conditional statement first executes the optional initial statement
(initial statement,
can be omitted, which means there is no initial action), and then determines whether conditional expression
is true
, if so, execute Code Block 1
, otherwise execute Code Block 2
. else {...}
may be omitted if no action is required if conditional_expression
is false
.
It should be noted that by default, statement ends with a line break, so the else
statement needs to be on the same line as the }
of the if
code block. If else
starts a new line, a compilation error will occur.
The following is an example of multiple conditional statement:
func Compare(x, y: int) => int {
if x < y {
return 1
} else if x > y {
return -1
} else {
return 0
}
}