FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/loopAndFlow/BreakExamples.java at master · Programing-Forks/Java-Programs · GitHub
Programing-Forks
/
Java-Programs
Public
forked from
divScorp/Java-Programs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programs
/
loopAndFlow
/
BreakExamples.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (45 loc) · 1019 Bytes
Breadcrumbs
Java-Programs
/
loopAndFlow
/
BreakExamples.java
Copy path
File metadata and controls
48 lines (45 loc) · 1019 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
loopAndFlow
;
public
class
BreakExamples
{
public
static
void
main
(
String
[]
args
) {
// Break statement breaks out of the loop
for
(
int
i
=
0
;
i
<
10
;
i
++) {
System
.
out
.
print
(
i
);
if
(
i
==
5
) {
break
;
}
}
// Output is 012345
// Break can be used in a while also
int
i
=
0
;
while
(
i
<
10
) {
System
.
out
.
print
(
i
);
if
(
i
==
5
) {
break
;
}
i
++;
}
// Output is 012345
System
.
out
.
println
();
// Break statement takes execution out of inner most loop
for
(
int
j
=
0
;
j
<
2
;
j
++) {
for
(
int
k
=
0
;
k
<
10
;
k
++) {
System
.
out
.
print
(
j
+
""
+
k
);
if
(
k
==
5
) {
break
;
// Takes out of loop using k
}
}
}
// Output is 000102030405101112131415
System
.
out
.
println
();
// To get out of an outer for loop, label's need to be used
outer
:
for
(
int
j
=
0
;
j
<
2
;
j
++) {
for
(
int
k
=
0
;
k
<
10
;
k
++) {
System
.
out
.
print
(
j
+
""
+
k
);
if
(
k
==
5
) {
break
outer
;
// Takes out of loop using j
}
}
}
// Output is 000102030405
}
}
Back
|
FazBrowse Home
|
New Git URL