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 — fix continue in for loops · justuni/java2python@0c6ee8e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • java2python/compiler
    • visitor.py
  • test
    • Continue0.java
    • Continue1.java
    • Continue2.java
    • ForLoop2.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎java2python/compiler/visitor.py‎

Copy file name to clipboardExpand all lines: java2python/compiler/visitor.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ def acceptCatch(self, node, memo):
407407

408408
def acceptContinue(self, node, memo):
409409
""" 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)
410414
contStat = self.factory.statement('continue', fs=FS.lsr, parent=self)
411415
if len(node.children):
412416
warn('Detected unhandled continue statement with label; generated code incorrect.')
Collapse file

‎test/Continue0.java‎

Copy file name to clipboardExpand all lines: test/Continue0.java
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ public static void main(String[] args) {
33
int x = 0;
44
while (x < 10) {
55
System.out.println(x);
6-
if (x==6) {
7-
break ;
6+
if (x == 6) {
7+
break;
88
} else {
9-
x+=2;
10-
continue ;
9+
x += 2;
10+
continue;
1111
}
12-
}
12+
}
1313
}
1414
}
Collapse file

‎test/Continue1.java‎

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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

‎test/Continue2.java‎

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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

‎test/ForLoop2.java‎

Copy file name to clipboard
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — 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.