Questions tagged [labeled-statements]

Labeled statements are names bound to blocks of code such as loops and conditional logic which can be referenced to allow flow control which is independent of source order

Labeled statements are useful for explicit control flow in complex logic such as nested loops.

References

17 questions
124
votes
12 answers

"loop:" in Java code. What is this, and why does it compile?

This code just made me stare at my screen for a few minutes: loop: for (;;) { // ... } (line 137 here) I have never seen this before, and I had no idea Java has a "loop" keyword (NetBeans doesn't even color it like a keyword), and it does…
Amy B
  • 17,874
  • 12
  • 64
  • 83
18
votes
2 answers

Label can only be used as part of a statement Error

I have been looking through the forums but I have not found an answer to this question that applies to my situation. I am trying to make a system call to using 'sort' (unix), however, I receive an error saying, "a label can only be part of a…
BologneseBandit
  • 187
  • 1
  • 1
  • 6
11
votes
4 answers

Why is this labeled javaScript continue not working?

I am using this code to weather some circles are overlapping: iCantThinkOfAGoodLabelName: x = genX(radius); y = genY(radius); for(i in circles) { var thisCircle = circles[i]; if(Math.abs(x-thisCircle["x"])+Math.abs(y-thisCircle["y"])>radius*2) {…
JJJollyjim
  • 5,837
  • 19
  • 56
  • 78
9
votes
1 answer

Is there such a thing as labeled or unlabeled break in C?

As is the case in Java where the break statement can be labeled or unlabeled, is there a statement in C which is either the equivalent or achieves the same process?
Antony Nepgen
  • 107
  • 2
  • 8
8
votes
3 answers

Please explain the usage of Labeled Statements

Is breaking and continuing the only uses of labeled statements in Java? When have you used Labeled Statements in your programs? Sorry the code snippet has been deleted. I am splitting the question
unj2
  • 52,135
  • 87
  • 247
  • 375
5
votes
1 answer

What happens in `let:let{let:[x=1]}=[alert(1)]`?

I’m watching a talk on JSON hijacking and not 2 minutes in, there is already JavaScript that is unfamiliar to me. let:let{let:[x=1]}=[alert(1)] It seems to work on Edge and just alerts 1, but I’ve never come across that let:let syntax. I’m curious,…
Ced
  • 15,847
  • 14
  • 87
  • 146
3
votes
2 answers

Javascript Conflicting Syntax Between Function As Object Key And Labeled Function in Block

Assuming you have a browser that supports both labeled function declarations and block statements, what is the standard way/method for browsers to determine if the following is an object with a property named L that is function F, or a block that…
2
votes
4 answers

Labeled break just after loop not working in Java

for(int x = 0; x < 5; x++) stop2: { System.out.println("Count"); if (x == 2) break stop2; } stop3: for(int x = 0; x < 5; x++) { …
mikeeei
  • 31
  • 6
1
vote
1 answer

Is it possible to use labeled statements with `throw`?

I have a chain of throwing calls that I need to catch, and then I need to use their result to - maybe - throw something anyway, despite all of them succeeding: func a() throws { do { let b = try b() if !b.valid { …
Isaaс Weisberg
  • 2,296
  • 2
  • 12
  • 28
1
vote
1 answer

Can the label for a break have any name?

I am learning java after coming over from python. The book I am reading is currently discussing breaks, which I am familiar with. When it comes to labeled breaks, can I give the label any name I choose (barring keywords)? Another thing, how do I end…
Caleb Suhy
  • 61
  • 7
1
vote
4 answers

Labeled loop in Java

I having been staring at my screen for a while and I do really need an explanation for labeled loop in this scenario: package com.misterkourouma.oca8.starter.test; public class LabeledLoop{ public static void main(String[] args) { int…
kourouma_coder
  • 1,078
  • 2
  • 13
  • 24
0
votes
0 answers

rbind DHS data labelled

For the context: For downloading DHS data I follow this link: https://rspatialdata.github.io/dhs-data.html#Loading_datasets_and_associating_its_metadata_into_R I want to analyze it following this post:…
Sulz
  • 333
  • 1
  • 8
0
votes
1 answer

Do we have labeled Statements in Typescript similar to what we have in JS?

I found this very interesting that we can break or continue a loop in Javascript. Do we have a similar concept in Typescript (Angular)? let str = ''; loop1: for (let i = 0; i < 5; i++) { if (i === 1) { continue loop1; } str = str +…
Ramin
  • 19
  • 6
0
votes
3 answers

how to jump from one for loop to another for loop using label in java?

when i am trying to access for loop from another loop i get following errors. how can i do that can somebody explain. public class Test { public static void main(String...rDX) { runing: for (int i = 1; i < 10; i++) …
0
votes
3 answers

iOS break loop with switch

I have a loop like this: label: for(X *y in z) { switch(y.num) { case ShouldDoSomething: [self somethingWithX:y]; break; case ShouldStopNow: y = [self valWhenStopped]; …
Ky -
  • 30,724
  • 51
  • 192
  • 308
1
2