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:
- Created 10 years ago
- Comments:9 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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;
orcontinue 3;
to break out of the first 2 loops or continue from the 3rd loop onwards, respectively.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.