[Solved] Increasing argument name in a for-loop [closed]


Individual parameters aren’t iterable; you’d need a collection for that.
Try changing it to an array instead:

public void increment(int increment1, int increment2, int increment3)
{
    int[] array = {increment1, increment2, increment3};

    for(int i = 1; i < array.length; i++){
      array[i] = 1;
    }
}

or

public void increment(int[] increment)
{
    for(int i = 1; i < increment.length; i++){
      increment[i] = 1;
    }
}

or

public void increment(int... increment)
{
    for(int i = 1; i < increment.length; i++){
      increment[i] = 1;
    }
}

Otherwise, you directly adress it:

increment1 = 1;
increment2 = 1;
increment3 = 1;

I see no reason to do this though. Parameters are for the method’s use. If you just going change all the values at the beginning of the method, you may as well exclude the parameters.

1

solved Increasing argument name in a for-loop [closed]