emojicode / emojicode

๐Ÿ˜€๐Ÿ˜œ๐Ÿ”‚ Worldโ€™s only programming language thatโ€™s bursting with emojis

Home Page:https://emojicode.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

break and continue statements

betseg opened this issue ยท comments

โญ๏ธ 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 โ—๏ธโ—๏ธ
  ๐Ÿ‰
๐Ÿ‰
commented

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.

commented

โน 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.

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

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.

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

commented

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...

commented

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