source: java2python/core/src/test/java/testcode/ForIfCase.java

Last change on this file was 1218, checked in by wouter, 6 weeks ago

#381 rewritten translation of for-loop

File size: 1.3 KB
Line 
1package testcode;
2
3import java.util.Arrays;
4import java.util.List;
5
6import org.eclipse.jdt.annotation.NonNull;
7
8public class ForIfCase {
9
10 static public void main(String[] args) {
11 @NonNull
12 String res = "";
13 for (int n = 1; n < 10; n = n + 1) {
14 res = res + Integer.toString(n);
15 switch (n) {
16 case 0:
17 res = res + " ";
18 break;
19 case 1:
20 res = res + "-";
21 // FALLTHROUGH
22 case 2:
23 case 3:
24 res = res + "%";
25 break;
26 default: // nothing
27 }
28 if (n > 5)
29 res = res + "*";
30 }
31 for (@NonNull
32 String x : Arrays.asList("a", "b", "c")) {
33 res = res + x;
34 }
35
36 // test assignment of variable inside loop.
37 for (Integer n; (n = getData()) != -1;) {
38 res = res + n.toString();
39 }
40
41 // #381 test continue inside loop.
42 for (Integer i = 0; i < 4; i += 1) {
43 if (i == 1)
44 continue;
45 res += i.toString();
46 }
47
48 @NonNull
49 Integer j = 1, k = 2;
50 for (@NonNull
51 Integer i = 0; j < 24; k += 1) {
52 if (k % 3 == 0)
53 continue;
54 res += (":" + i.toString() + "," + j.toString() + ","
55 + k.toString());
56 j = 2 * k;
57 }
58
59 System.out.println(res);
60
61 }
62
63 private static final @NonNull List<@NonNull Integer> data = Arrays.asList(1,
64 2);
65 private static @NonNull Integer index = 0;
66
67 private static int getData() {
68 if (index >= data.size())
69 return -1;
70 int d = data.get(index);
71 index = index + 1;
72 return d;
73 }
74}
Note: See TracBrowser for help on using the repository browser.