GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java-Programs/loopAndFlow/BreakExamples.java at master · divScorp/Java-Programs

Expand file tree

/

BreakExamples.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
48 lines (45 loc) · 1019 Bytes
/

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
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.