groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From OC <...@ocs.cz>
Subject can't declare more variables in a loop?
Date Tue, 18 Aug 2015 21:00:24 GMT
Hello there,

is this a parser bug, or am I overlooking something of importance?

===
17 /tmp> <q.groovy 
def foo() {
  int n=1,m=2; // allright
  println "$n $m"
}
def bar() {
  for (int n=1,m=2;n<m;n++) println "$n" // oops
}
18 /tmp> groovy q 
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/private/tmp/q.groovy: 6: unexpected token: = @ line 6, column 13.
     for (int n=1,m=2;n<m;n++) println "$n" // oops
               ^

1 error

19 /tmp> groovy -v
Groovy Version: 2.3.8 JVM: 1.7.0_13 Vendor: Oracle Corporation OS: Mac OS X
20 /tmp> 
===

Note, incidentally, that Java has this right:

===
25 /tmp> <q.java 
class q {
  public static void main(String[] args) {
    for (int n=1,m=2;n<m;n++) System.out.println("-> "+n);
  }
}
26 /tmp> javac q.java && java q
-> 1
27 /tmp> 
===

Thanks and all the best,
OC


Mime
View raw message