-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
doc: please document the mean of "blk" #1327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'll leave this issue open until this answer is available in the official docs, but to answer your question:
const result = this_is_a_label: {
break :this_is_a_label i32(1234);
};
assert(result == 1234); |
Here is my understanding: |
@bronze1man you bring up a good point comparing
I like that Zig builds on this concept by not only extending control flow in blocks, but allows the returning of values. |
something that strikes me about the example code in the OP is that we maybe shouldn't allow loops to return values. You can accomplish that with block break statements, which i think is clearer anyway: const result = blk: for (items) |value| {
if (value == null) {
break :blk 9;
} else {
sum += value.?;
}
} else {
assert(sum == 7);
break :blk sum;
}; |
@thejoshwolfe why not? |
@thejoshwolfe related to #1004 |
What about the proposed result keyword? #732
|
I have seen some code:
What is blk mean in here? Why the
break 9
do not haveblk
?And the
Grammar
part do not haveblk
in it.This is the biggest unknown for me.
The text was updated successfully, but these errors were encountered: