function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anu Raj.ax1269Anu Raj.ax1269 

for loop with more that 1 variable

Is it possible to use more than 2 variable in a for loop.

i tried this

for(integer j=0, k=1; 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.







for(integer a=1,b=5; a<b; a++) {
System.debug('a = ' + a);
System.debug('b = ' + b);

James LoghryJames Loghry

You're missing the condition in the middle of the loop syntax.


But can I ask why you're keeping two variables?  The pseudo code looks like you have one variable that is 1 more than the other each iteration.  Why not use j+1 inside the loop?