aboutsummaryrefslogtreecommitdiff
path: root/doc/docs/doc/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/docs/doc/README.md')
-rwxr-xr-xdoc/docs/doc/README.md47
1 files changed, 47 insertions, 0 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md
index 5b8fc59..57f27c8 100755
--- a/doc/docs/doc/README.md
+++ b/doc/docs/doc/README.md
@@ -2161,6 +2161,53 @@ f2 arg1, arg2
2161</pre> 2161</pre>
2162</YueDisplay> 2162</YueDisplay>
2163 2163
2164### Prefixed Return Expression
2165
2166When working with deeply nested function bodies, it can be tedious to maintain readability and consistency of the return value. To address this, YueScript introduces the **Prefixed Return Expression** syntax. Its form is as follows:
2167
2168```moon
2169findFirstEven = (list): nil ->
2170 for item in *list
2171 if type(item) == "table"
2172 for sub in *item
2173 if sub % 2 == 0
2174 return sub
2175```
2176<YueDisplay>
2177<pre>
2178findFirstEven = (list): nil ->
2179 for item in *list
2180 if type(item) == "table"
2181 for sub in *item
2182 if sub % 2 == 0
2183 return sub
2184</pre>
2185</YueDisplay>
2186
2187This is equivalent to:
2188
2189```moon
2190findFirstEven = (list) ->
2191 for item in *list
2192 if type(item) == "table"
2193 for sub in *item
2194 if sub % 2 == 0
2195 return sub
2196 nil
2197```
2198<YueDisplay>
2199<pre>
2200findFirstEven = (list) ->
2201 for item in *list
2202 if type(item) == "table"
2203 for sub in *item
2204 if sub % 2 == 0
2205 return sub
2206 nil
2207</pre>
2208</YueDisplay>
2209
2210The only difference is that you can move the final return expression before the `->` or `=>` token to indicate the function’s implicit return value as the last statement. This way, even in functions with multiple nested loops or conditional branches, you no longer need to write a trailing return expression at the end of the function body, making the logic structure more straightforward and easier to follow.
2164 2211
2165## Backcalls 2212## Backcalls
2166 2213