-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabelStatement.java
More file actions
58 lines (47 loc) · 1.39 KB
/
Copy pathLabelStatement.java
File metadata and controls
58 lines (47 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package Phase1_CoreLanguage.DecisionMaking.JumpStatement;
/**Java does not have a goto statement because it provides a way to branch in an arbitrary and unstructured manner.
* Java uses label. A Label is use to identifies a block of code.
Syntax:
label:
{
statement1;
statement2;
statement3;
.
.
}
Now, break statement can be use to jump out of target block.
Note: You cannot break to any label which is not defined for an enclosing block.
Syntax:
break label;**/
public class LabelStatement {
public static void main(String args[])
{
boolean t = true;
// label first
first:
{
// Illegal statement here as label second is not
// introduced yet break second;
second:
{
third:
{
// Before break
System.out.println("Before the break statement");
// break will take the control out of
// second label
if (t)
break second;
System.out.println("This won't execute.");
}
System.out.println("This won't execute.");
}
// Third block
System.out.println("This is after second block.");
}
}
//OUTPUT
//Before the break.
//This is after second block.
}