Java: 2-assignments-2-initializations inside for-loop not allowed?

Posted by HH on Stack Overflow See other posts from Stack Overflow or by HH
Published on 2010-04-11T02:56:20Z Indexed on 2010/04/11 3:03 UTC
Read the original article Hit count: 315

$ javac MatchTest.java 
MatchTest.java:7: ')' expected
        for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
                ^
MatchTest.java:7: ';' expected
        for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
                               ^
MatchTest.java:7: ';' expected
        for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
                                             ^
MatchTest.java:7: not a statement
        for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
                                                ^
MatchTest.java:7: illegal start of expression
        for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
                                                                          ^
5 errors
$ cat MatchTest.java 
import java.util.*;
import java.io.*;

public class MatchTest {
    public static void main(String[] args){
        String text = "hello0123456789hello0123456789hello1234567890hello3423243423232";
        for((int i=-1 && String match="hello"); (i=text.indexOf(match)+1);)
            System.out.println(i);
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about assignment