-
Notifications
You must be signed in to change notification settings - Fork 159
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
break and continue statements #153
Comments
I haven’t heard of "breaking with a value" before. The same behavior could be easily achieved with a method, couldn’t it? |
Yeah, it can be. |
⏹ is nice. ⏭ conflicts with https://www.emojicode.org/docs/packages/s/23e9.html#i⏭ though. |
And what about breaking out of/continuing nested loops? Some languages have labels for that purpose. Example from Rust: fn main() {
'outer: loop {
println!("Entered the outer loop");
'inner: loop {
println!("Entered the inner loop");
// This would break only the inner loop:
//break;
// This breaks the outer loop:
break 'outer;
}
println!("This point will never be reached");
}
println!("Exited the outer loop");
} |
Actually, I have rarely seen breaking to a specific loop being used in real production code, so I doubt it is something people will want to do in Emojicode. Moreover, it adds complexity to the reasoning the compiler does about flow control. I’m not totally against this, but I don’t feel like implementing this myself. |
|
JavaScript, Java and Go, implement exactly this feature, for instance. C++, C and C# have labels with |
Thanks to the latest changes, ⏭ is no longer in use in the s package. We could use it for the 'continue' statement now. |
⭐️ Proposed change
Adding
⏹
forbreak
ing from a loop (maybe with a value like Rust does?) and⏭
forcontinue
ing a loop. This may be even improved with labelled loops, tho its syntax would be harder to be agreed upon.🤔 Rationale
A useful feature. I chose ⏭ because Unicode defines it as "next track", and ⏹ is "stop".
🕺Example
"Standard"
break
:break
ing with a value:continue
:The text was updated successfully, but these errors were encountered: