ブロックとスコープ
コードブロック
A block in Rust contains a sequence of expressions, enclosed by braces {}
. Each block has a value and a type, which are those of the last expression of the block:
最後の式が ;
で終了した場合、ブロック全体の値と型は ()
になります。
Speaker Notes
This slide and its sub-slides should take about 5 minutes.
- ブロック内にある最後の行を変更することによって、ブロック全体の値が変わることが分かります。例えば、行末のセミコロンを追加/削除したり、
return
を使用したりすることで、ブロックの値は変化します。