question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Control flow labels

See original GitHub issue

[@FroMage] It has happened to me more than once that I have two interleaved loops and I need to be able to break/continue out of the inner one and I can’t and the resulting code looks terribly messy.

Now, I agree these situations are not super common, so if adding labels as they are in Java is out of the question, I think we can make it work without introducing new syntax and reuse compiler annotations for that:

@read
while(true){
 Integer byte = read();
 if(byte == 2){
   special code that says we need to read 2 more bytes
   for(b in 1..2){
     Integer otherByte = read();
     if(otherByte == -1){
       @read break;
     }
   }
 }
 print("got a byte: ``byte``");
}

I guess that would work, and we can make the typechecker check these labels and the backend should be able to use JVM and JSVM labels.

This is not urgent, but still useful and not intrusive.

[Migrated from ceylon/ceylon-spec#939]

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
phlopsicommented, Sep 15, 2017

Why not simply introduce goto and let us jump out of everything? :trollface:

Joke aside, not being able to get out of multiple loops is kinda annoying. While I do prefer labels, another solution would be to specify a number in the form of break 2; or continue 3; to break out of the first 2 loops or continue from the 3rd loop onwards, respectively.

1reaction
RossTatecommented, Feb 23, 2016

Y’all don’t let people break/continue from multiple loops?! I thought y’all wanted a “regular” language!

As for how to do it, annotations seems odd. I don’t really view annotations as critical to code execution; they are annotations onto code. Ceylon does have more heavily integrated annotations, so maybe it makes some sense. Is it that hard to make it part of the syntax?

Also, because this keeps coming up, one related feature request: When a for/while loop is labeled, let me use that label to check whether I’m in the first iteration of the loop. It’d save so much boilerplate.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flow labeling - IBM
This flow identification can be used for priority control, but might also be used for any number of other controls. The flow label...
Read more >
Labels & Control Flow — Ren'Py Documentation
Label statements allow the given name to be assigned to a program point. They exist solely to be called or jumped to, either...
Read more >
How to use labels to control the Flow in JavaScript?
To control the flow in JavaScript, use labels. A label can be used with break and continue statement to control the flow more...
Read more >
Flow control actions - Power Automate - Microsoft Learn
Labels are used to create points of reference for the Go to action that changes the running point of the desktop flow. The...
Read more >
Flow Labels (IPv6 Administration Guide)
A flow is a sequence of packets that are sent from a particular source to a particular, unicast or multicast, destination. The source...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found