GeezerVison is showing github.com — fix continue in for loops · justuni/java2python@0c6ee8e
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: java2python/compiler/visitor.py +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -407,6 +407,10 @@ def acceptCatch(self, node, memo): |
407 | 407 |
|
408 | 408 | def acceptContinue(self, node, memo): |
409 | 409 | """ Accept and process a continue statement. """ |
| 410 | + parent = node.parents(lambda x: x.type in {tokens.FOR, tokens.FOR_EACH, tokens.DO, tokens.WHILE}).next() |
| 411 | + if parent.type == tokens.FOR: |
| 412 | + updateStat = self.factory.expr(parent=self) |
| 413 | + updateStat.walk(parent.firstChildOfType(tokens.FOR_UPDATE), memo) |
410 | 414 | contStat = self.factory.statement('continue', fs=FS.lsr, parent=self) |
411 | 415 | if len(node.children): |
412 | 416 | warn('Detected unhandled continue statement with label; generated code incorrect.') |
|
Collapse file
Copy file name to clipboardExpand all lines: test/Continue0.java +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,12 +3,12 @@ public static void main(String[] args) { |
3 | 3 | int x = 0; |
4 | 4 | while (x < 10) { |
5 | 5 | System.out.println(x); |
6 | | - if (x==6) { |
7 | | - break ; |
| 6 | + if (x == 6) { |
| 7 | + break; |
8 | 8 | } else { |
9 | | - x+=2; |
10 | | - continue ; |
| 9 | + x += 2; |
| 10 | + continue; |
11 | 11 | } |
12 | | - } |
| 12 | + } |
13 | 13 | } |
14 | 14 | } |
Collapse file
Copy file name to clipboard +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +class Continue1 { |
| 2 | + public static void main(String[] args) { |
| 3 | + int[] ints = {1, 2, 3, 4, 5, 6, 7}; |
| 4 | + for (int x : ints) { |
| 5 | + if (x == 6) { |
| 6 | + break; |
| 7 | + } else if (x == 3) { |
| 8 | + continue; |
| 9 | + } |
| 10 | + System.out.println(x); |
| 11 | + } |
| 12 | + } |
| 13 | +} |
Collapse file
Copy file name to clipboard +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +class Continue2 { |
| 2 | + public static void main(String[] args) { |
| 3 | + int x = 0; |
| 4 | + do { |
| 5 | + System.out.println(x); |
| 6 | + if (x == 6) { |
| 7 | + break; |
| 8 | + } else { |
| 9 | + x += 2; |
| 10 | + continue; |
| 11 | + } |
| 12 | + } while (x < 10); |
| 13 | + } |
| 14 | +} |
Collapse file
Copy file name to clipboard +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +class ForLoop2 { |
| 2 | + public static void main(String[] args) { |
| 3 | + for (int i = 0; i < 3; i++) { |
| 4 | + if (i == 1) |
| 5 | + continue; |
| 6 | + System.out.println(i); |
| 7 | + } |
| 8 | + } |
| 9 | +} |