Skip to content
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

Open
betseg opened this issue Dec 26, 2019 · 8 comments
Open

break and continue statements #153

betseg opened this issue Dec 26, 2019 · 8 comments
Labels

Comments

@betseg
Copy link
Contributor

betseg commented Dec 26, 2019

⭐️ Proposed change

Adding for breaking from a loop (maybe with a value like Rust does?) and for continueing 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:

0 ➡️ 🖍🆕a
🔁 👍 🍇
  a ⬅️➕ 1
  ↪️ a ▶️ 5 🍇
    ⏹
  🍉
🍉

breaking with a value:

0 ➡️ 🖍🆕a
🔁 👍 🍇
  a ⬅️➕ 1
  ↪️ a ▶️ 5 🍇
    ⏹ a ❗️
  🍉
🍉 ➡️ thisVarIsSix

continue:

0 ➡️ 🖍🆕sum
🔂 i 🆕⏩⏩ 0 10❗️ 🍇
  ↪️ i 🚮 2 🙌 1 🍇
    ⏭
  🍉
  🙅 🍇
    sum ⬅️➕ i
    😀 🔡 sum 10 ❗️❗️
  🍉
🍉
@betseg betseg changed the title break and continue statements break and continue statements Dec 26, 2019
@thbwd
Copy link
Member

thbwd commented Dec 26, 2019

I haven’t heard of "breaking with a value" before. The same behavior could be easily achieved with a method, couldn’t it?

@betseg
Copy link
Contributor Author

betseg commented Dec 26, 2019

Yeah, it can be.

@thbwd thbwd added the proposal label Jan 1, 2020
@thbwd
Copy link
Member

thbwd commented Jan 2, 2020

⏹ is nice. ⏭ conflicts with https://www.emojicode.org/docs/packages/s/23e9.html#i⏭ though.
I don’t think that "breaking with a value" is something that fits Emojicode particularly well.

@betseg
Copy link
Contributor Author

betseg commented Jan 2, 2020

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");
}

@thbwd
Copy link
Member

thbwd commented Jan 3, 2020

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.

@betseg
Copy link
Contributor Author

betseg commented Jan 3, 2020

what if it's not used because it's not in many languages sorry

@thbwd
Copy link
Member

thbwd commented Jan 3, 2020

JavaScript, Java and Go, implement exactly this feature, for instance. C++, C and C# have labels with goto which would cover this use case. I think that covers a lot of code being written today...

@thbwd
Copy link
Member

thbwd commented Jan 9, 2020

Thanks to the latest changes, ⏭ is no longer in use in the s package. We could use it for the 'continue' statement now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants