mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 09:24:36 +00:00
manual: document block expression (#11638)
(cherry picked from commit b64dd795b1)
This commit is contained in:
@@ -3088,6 +3088,21 @@ As seen in the above example, the case expression can also introduce side
|
||||
effects. When multiple statements are given for a branch, Nim will use
|
||||
the last expression as the result value.
|
||||
|
||||
Block expression
|
||||
----------------
|
||||
|
||||
A `block expression` is almost like a block statement, but it is an expression
|
||||
that uses last expression under the block as the value.
|
||||
It is similar to the statement list expression, but the statement list expression
|
||||
does not open new block scope.
|
||||
|
||||
.. code-block:: nim
|
||||
let a = block:
|
||||
var fib = @[0, 1]
|
||||
for i in 0..10:
|
||||
fib.add fib[^1] + fib[^2]
|
||||
fib
|
||||
|
||||
Table constructor
|
||||
-----------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user