Reputation: 39
Is it possible to use more than 2 variable in a for loop.
i tried this
for(integer j=0, k=1; j<iSize.size(); j++, k++) {
}
and getting this error Error: Compile Error: expecting a right parentheses, found ',' at line 188 column 53
Please help me to find the solution. Thanks Anu
Upvotes: 1
Views: 1763
Reputation: 486
No, in this case since there is only one condition to end the loop you could write the following:
integer k = 1;
for (integer j=0; j < iSize.size(); j++)
{
k++;
//Code goes here
}
if you actually needed two loops you could do
for (integer j=0; j < iSize.size(); j++)
{
for (integer k = 1; k < Some_Condition; k++)
{
//Code goes here
}
}
Following either of these suggestions should clear up that error. [Edit] The code you have now is in an incorrect format and the compiler is expecting the closing paren since you can only put 1 statement at the end of the for loop and you have 2.
Upvotes: 4