Understanding return and yield
The return
statement may sound familiar, and indeed the function it fulfills in Bosque scripts is the same function as in most languages. Within a block of code, it ends the invocation returning the expression's value as a result.
Let's understand this with the help of some examples:
namespace NSMain; entrypoint function main(): String { return "hello world"; }
If we analyze the classic hello world
, we will see that the input function is composed of a single return
statement, so when we execute our script, the expression is evaluated, the execution is ended, and the text "hello world"
is returned as a result.
So, if we try to add a second return
statement below the first one, the execution of this second line will not be carried out because the first one ends the block's execution. The following code shows the line that won't be executed:
namespace NSMain; entrypoint function...