File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -142,5 +142,23 @@ fn foo(x: i32) -> i32 {
142
142
}
143
143
```
144
144
145
+ The previous definition without ` return ` may look a bit strange if you haven't
146
+ worked in an expression-based language before, but it becomes intutive over
147
+ time. If this were production code, we wouldn't write it in that way anyway,
148
+ we'd write this:
149
+
150
+ ``` rust
151
+ fn foo (x : i32 ) -> i32 {
152
+ if x < 5 {
153
+ x
154
+ } else {
155
+ x + 1
156
+ }
157
+ }
158
+ ```
159
+
160
+ Because ` if ` is an expression, and it's the only expression in this function,
161
+ the value will be the result of the ` if ` .
162
+
145
163
There are some additional ways to define functions, but they involve features
146
164
that we haven't learned about yet, so let's just leave it at that for now.
You can’t perform that action at this time.
0 commit comments