Julia introduced Compound expressions, which allow you to execute multiple expressions with a single value.
This can be achieved using begin
and end
keywords.
variable = begin
expression1
expression2
expression3
end
We can replace the above expressions into a single expression using the ;
symbol.
variable = begin expression1; expression2; expression3; end
Here is an example
result = begin first = 2; second = 13; first * second end
Above Simplified using the below expression
(first = 1;
second = 2;
first * second)
Variable scope inside begin blocks.
The variables do not have any local scope until the local variable is declared.