MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

control/BreakAndContinue.java:9–32  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

7
8public class BreakAndContinue {
9 public static void main(String[] args) {
10 for(int i = 0; i < 100; i++) { // [1]
11 if(i == 74) break; // Out of for loop
12 if(i % 9 != 0) continue; // Next iteration
13 System.out.print(i + " ");
14 }
15 System.out.println();
16 // Using for-in:
17 for(int i : range(100)) { // [2]
18 if(i == 74) break; // Out of for loop
19 if(i % 9 != 0) continue; // Next iteration
20 System.out.print(i + " ");
21 }
22 System.out.println();
23 int i = 0;
24 // An "infinite loop":
25 while(true) { // [3]
26 i++;
27 int j = i * 27;
28 if(j == 1269) break; // Out of loop
29 if(i % 10 != 0) continue; // Top of loop
30 System.out.print(i + " ");
31 }
32 }
33}
34/* Output:
350 9 18 27 36 45 54 63 72

Callers

nothing calls this directly

Calls 2

printMethod · 0.80
rangeMethod · 0.80

Tested by

no test coverage detected