Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple variables in a for loop

Tags:

java

for-loop

          else
    {
        r=Power(s,n-1);
        System.out.println(r);
        int d=r.length;
        char ch=s.charAt(n);
        int v=d+1;
        p[v]=Character.toString(ch);
        String q = p[v];

        for(i=d+2,j=0;i<2d+3,j<d;i++,j++)
        {
            p[i]=r[j].concat(q);
        }
}

A syntax error is shown and var j is not recognized even after declaration... pls help me.

like image 587
Priyanka Avatar asked Oct 27 '12 12:10

Priyanka


1 Answers

The problem is the condition of the loop. The correct should be:

for(i=d+2,j=0;i<2d+3 && j<d;i++,j++){ ...

or

for(i=d+2,j=0;i<2d+3 || j<d;i++,j++){ ...

There is no meaning in putting a comma separating two boolean conditions in java.

And as seen in the comments, variables j and i are not declared.

like image 118
Renato Lochetti Avatar answered Sep 22 '22 19:09

Renato Lochetti