jeudi 4 septembre 2014

If on a certain element of the array in a loop, do X action


Vote count:

0




Is there a way to see that, if a loop is on a certain element of an array, to do a specific action?


Say that if I'm on the first element of an array in a loop, set a flag to false?


ex)



int carry = 1;
int arraySum[] = new int[NUM_DIGITS];
boolean carryFlag = false;
for(int i = NUM_DIGITS - 1; i >= 0; i--){

arraySum[i] = array1[i] + array2[i];
if(carryFlag){
arraySum[i] += carry;
carryFlag = false;
}

//if on the last iteration/element of the array,
//arraySum[0], carryFlag = false; and continue;

if(arraySum[i] > 9){
arraySum[i] = arraySum[i] - 10;
carryFlag = true;
}
}


Sorry if my question sounds rather vague.. But if there's a way around to making it act like a boolean: if(arraySum[0]) carryFlag = false



asked 30 secs ago







If on a certain element of the array in a loop, do X action

Aucun commentaire:

Enregistrer un commentaire