The block expression consists of a sequence of expressions.
A block expression is surrounded by curly braces. The expressions in a block can be terminated by an optional semicolon.
{
<sequence of expressions>
}
The value of the last expression in the block is returned as the value of the complete block.
The type of a block is the returned type (i.e., of the last expression). Empty blocks return
null
and have the type Object
.
In the following example, the block type is String
because the last expressions in all the
possible execution paths are all of type String
.
{
var x = greeting
if (x == "Hello") {
x + " World!"
} else {
x
}
}
This documentation is inspired by the documentations from the Xtext and Xtend projects.
Copyright © 2014-2024 SARL.io, the Original Authors and Main Authors.
Documentation text and medias are licensed under the Creative Common CC-BY-SA-4.0; you may not use this file except in compliance with CC-BY-SA-4.0. You may obtain a copy of CC-BY-4.0.
Examples of SARL code are licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the Apache License. You may obtain a copy of the Apache License.
You are free to reproduce the content of this page on copyleft websites such as Wikipedia.
Generated with the translator docs.generator 0.14.0.